Alexchenys

prime2

Feb 20th, 2018
91
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.  
  3. int main()
  4. {
  5.     int num, i;
  6.     printf("Enetr a number. We can check if it is a prime number.\n");
  7.     scanf("%d",&num);
  8.  
  9.     if(num == 1)
  10.     {
  11.         printf("%d is not a prime number",num);// 1 is not a prime numebr. When num == 1, return 0.
  12.         return 0;
  13.     }
  14.     else
  15.     {
  16.         for(i = 2; i < num; i++)
  17.         {
  18.             if(num % i == 0)
  19.             {
  20.                 printf("%d is not a prime number",num);
  21.                 return 0;
  22.             }
  23.         }
  24.         printf("%d is a prime number",num);
  25.         return 0;  
  26.     }
  27. }
Add Comment
Please, Sign In to add comment