#include(iostream.h) // place this '<' & '>' instead of '(' & ')' before iostream.h
#include(conio.h)
void main( )
{
int n, x, flag,ct;
clrscr( );
cout<<"Enter the n value:"; cin>> n;
cout<<"Prime Numbers:";
for( ct=1; ct<=n; ct++)
{
x=2; flag=0;
while(x<=ct/2)
{
if(ct%x==0) { flag=1; break; }
x++;
}
if(flag==0)
cout<< ct;
}
getch( );
}
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Wednesday, February 25, 2009
Subscribe to:
Post Comments (Atom)
if it is possible to write a program to generate perfect numbers?
ReplyDeletecould you explain the logic of flag in it? and the loop also
ReplyDeleteThis comment has been removed by the author.
Deletecould you explain the logic of flag in it? and the loop also
ReplyDelete