Monday 8 July 2013

Print prime numbers from 1 to 1000 in C++

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int a,b,temp;
   
    cout<<"--------------------------------\n";       
    cout<<"  Prime Numbers from 1 to 1000  \n";
    cout<<"--------------------------------\n\n";
   
    for(a = 2 ; a <= 1000 ; 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