Wednesday 10 July 2013

Prime Numbers from 1 to 500 in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a,b,temp;
  
    cout<<"--------------------------------\n";      
    cout<<"  Prime Numbers from 1 to 500  \n";
    cout<<"--------------------------------\n\n";
  
    for(a = 2 ; a <= 500 ; a++)
    {
        temp=0;
        for(b = 2 ; b < a ; b++)
        {
            if(a % b == 0)  
            temp = 1;  
        }
        if(temp == 0)
        cout<<a<<" ,";
    }  
    getch();
}

No comments:

Post a Comment