Monday, June 18, 2012

To find whether the given number is prime or not


/* To find whether the given number is prime or not */
#include<stdio.h>
#include<conio.h>
void main()
{
  int i,num;
  clrscr();
  printf("Enter the number: ");
  scanf("%d",&num);
  i=2;
  while(i<=num-1)
  {
    if(num%i==0)
    {
      printf("\n%d is NOT a prime number!",num);
      break;
    }
    i++;
  }
  if(i==num)
    printf("%d is a Prime Number!",num);
  getch();
}
 
OUTPUT
Enter the number: 67
67 is a Prime Number!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.