Advertisement
Shailrshah

Check for Prime number

May 27th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.         int prime=1,i,n;
  5.         printf("Enter the prime number: ");
  6.         scanf("%d",&n);
  7.         if (n<=2)
  8.                 goto x;
  9.         for(i=2; i<=n/2; i++)
  10.         {
  11.                 if(n%i==0)
  12.                 {
  13.                         x: prime = 0;
  14.                         break;
  15.                 }
  16.         }
  17.         if(prime == 0)
  18.                printf("Not prime!");
  19.         else
  20.                 printf("Prime!");
  21.         fflush(stdin);
  22.         getchar();
  23.         return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement