#include<stdio.h>
#include<math.h>
void main()
{
int i,num,lim,flag,count=0;
clrscr();
printf("Enter the no.of prime numbers:");
scanf("%d",&lim);
printf("1st %d prime numbers are :\n",lim);
for(num=2;count<lim;++num)
{
flag=1;
for(i=2;i<=sqrt(num);++i)
{
if(num%i==0)
{
flag=0;
break;
}
}
if(flag)
{
printf("%d\t",num);
++count;
}
}
getch();
}
#include<math.h>
void main()
{
int i,num,lim,flag,count=0;
clrscr();
printf("Enter the no.of prime numbers:");
scanf("%d",&lim);
printf("1st %d prime numbers are :\n",lim);
for(num=2;count<lim;++num)
{
flag=1;
for(i=2;i<=sqrt(num);++i)
{
if(num%i==0)
{
flag=0;
break;
}
}
if(flag)
{
printf("%d\t",num);
++count;
}
}
getch();
}
No comments:
Post a Comment