C++ Program to display prime numbers upto n.

C++ Program to display prime numbers upto n.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,z;
cout<<"Enter a number: ";
cin>>a;
cout<<"The prime numbers upto "<<a<<" are: "<<endl;
for(b=2;b<=a;b++)
{
z=0;
for(c=1;c<=b;c++)
{
if(b%c==0)
z++;
}
if(z==2)
cout<<b<<" ";
}
getch();
}


Learn More :