Programming Languages

PROGRAM TO FIND PRIME NUMBERS USING FUNCTION

/* PROGRAM TO FIND PRIME NUMBERS USING FUNCTION */

#include<stdio.h>
#include<conio.h>

void prime(int n);
void main()
{
int n;
textcolor(69);
clrscr();
printf(“\n ENTER HOW MANY PRIME NUMBERS YOU WANTS TO FIND :”);
scanf(“%d”,&n);
prime(n);
getch();
}
void prime(int n)
{
int x,i,j,count=0;
for(i=2;i<=10000;i++)
{
x=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
x=1;
break;
}
}
if(x==0)
{
count++;
if(count<=n)
printf(“\t%d”,i);
}
}
}

ANIL VERMA
Hello Everyone, Welcome to A. V. Powertech.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.