//B4. C Program to generate n prime numbers by defining isprime function.
#include<stdio.h>
#include<conio.h>
void isprime(int); //Function prototype declaration.
void main()
{
int n;
clrscr();
printf("How many prime numbers are required? \n");
scanf("%d", &n);
printf("Prime numbers are:\n");
isprime(n);
}
void isprime(int n)
{
int count=1,flag, i=2,j;
/* Generating prime numbers */
while(count <= n)
{
flag = 0;
for(j=2; j <= i/2; j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("%d\n",i);
count++;
}
i++;
}
getch();
}
Search This Blog
Wednesday, 2 March 2022
B4. C Program to generate n prime numbers by defining isprime function.
Labels:
NEP_C_Programs
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment