Prime Numbers in C

A prime number is a natural number that is not a product of two smaller natural numbers. The natural number 1 is not a prime number. The natural number must be greater than 1.

Below program is to find the n term of prime number.

#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i,j,flag=0;
 clrscr();
 printf("\nEnter the no of terms: ");
 scanf("%d",&n);
 printf("\n\nPrime No:\n");
 for(i=1;i<=n;i++)
 {
  for(j=1;j<i;j++)
  {
    if(i%j==0)
    {
     flag=1;
     goto x;
    }
  }
  if((flag==0)&&(i!=1))
   printf("\n%d",i);
  x:flag=0;
 }

getch();
}

 

Leave a Reply