Code In Tech - The Ultimate World of Computer Technology

Saturday 24 March 2012

C Program to list of prime numbers till n

SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
 int i,j,n,flag=0;
 clrscr();
 printf("Enter number:");
 scanf("%d",&n);
 for(i=3;i<n;i++)
 {

  for(j=2;j<i;j++)
  {
   if(i%j==0)
   {
    flag=1;
    break;
   }
   else
   {
    flag=0;
   }
  }
  if(flag==0)
  {
   printf("%d, ",i);
  }
 }
 getch();
}

No comments :

Post a Comment