Code In Tech - The Ultimate World of Computer Technology

Saturday, 24 March 2012

C program to check number is prime or not

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

  if(n%i==0)
  {
   flag=1;
   break;
  }
 }
 if(flag==1)
 {
  printf("it is not prime.");
 }
 else
 {
  printf("it is prime.");
 }
 getch();
}

No comments :

Post a Comment