#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,num,i,flag;
clrscr();
cout<<"enter the limit\n";
cin>>n;
cout<<"the prime numbers up to\t"<<n<<" are:";
for(num=2;num<=n;num++)
{
flag=1;
for(i=2;i<=sqrt(num);i++)
if(num%i==0)
{
flag=0;
break;
}
if(flag)
{cout<<"\t"<<num;
}}
getch();
}
OUTPUT:
enter the limit
25
the prime numbers up to 25 are:
2 3 5 7 11 13 17 19 23
0 comments:
Post a Comment