Advertisement
Guest User

Untitled

a guest
Jan 14th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. /* Check whether a number given is prime or not.*/
  5.  
  6. main()
  7. {
  8.     int A, num;
  9.    
  10.     #define max 2147483647
  11.     #define min -2147483648
  12.  
  13.     printf("Enter an integer between and including -2147483648 and 2147483647: ");
  14.     scanf("%d", &num);
  15.  
  16.     if(num < min || num > max){
  17.         printf("This is not a valid input. Aborting.\n");
  18.         return 0;
  19.     }
  20.    
  21.     for(A=2; A<num/2; A++){
  22.         if(num % A == 0){
  23.             printf("%d is not a prime number. It is completely divisible by %d.\n",num,A);
  24.             return 0;
  25.         }
  26.     }
  27.     printf("%d is a prime number.\n",num);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement