rootUser

check input is prime or not

May 26th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* C program to check whether a number is prime or not. */
  2. #include <stdio.h>
  3. int main()
  4. {
  5.   int n, i, flag=0;
  6.   printf("Enter a positive integer: ");
  7.   scanf("%d",&n);
  8.   for(i=2;i<=n/2;++i)
  9.   {
  10.       if(n%i==0)
  11.       {
  12.           flag=1;
  13.           break;
  14.       }
  15.   }
  16.   if (flag==0)
  17.       printf("%d is a prime number.",n);
  18.   else
  19.       printf("%d is not a prime number.",n);
  20.   return 0;
  21. }
Add Comment
Please, Sign In to add comment