Write a C Program to Generate n Prime Numbers
Source Code:
#include <stdio.h>
int main()
{
int n, prime=3, count, c;
printf("Enter number of prime numbers:");
scanf("%d",&n);
if(n>=1)
printf("Prime Numbers are \n 2");
for(count=2;count<=n;prime++)
{
for(c=2;c<prime;c++)
{
if(prime%c==0)
break;
}
if(c==prime)
{
printf("\n %d",prime);
count++;
}
}
return 0;
}
Output:
No comments:
Post a Comment