Wednesday 28 March 2012


TO DISPLAY THE FIRST ‘N’ RPIME NUMBERS




#include<stdio.h>
#include<math.h>
Void main()
{
Int num,i,n,flag,count=0;
Clrscr();
Printf(“how many prime number ?”);
Scanf(“%d”,&n);
Printf(“first %d prime numbers are :\n”,n);
For(num=2;count<=n;++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