- Program for Prime Number Generation
#include<stdio.h>
main()
{
int n,i=1,j,c;
clrscr();
printf("Enter Number Of Terms");
printf("Prime Numbers Are Follwing");
scanf("%d",&n);
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d ",i);
i++;
}
getch();
}
Output-------->
----------------
- Program to findout all Prime Number between 1 to 100.
#include<stdio.h>
void main()
{
int i,num=1;
clrscr();
while(num<=100)
{
i=2;
while(i<=num)
{
if(num%i==0)
break;
i++;
}
if(i==num)
printf(" %d",num);
num++;
}
printf(" all are Prime");
getch();
}
Output-------->
No comments:
Post a Comment