Advertisement
vencinachev

Prime number

Mar 6th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.     int number, i, n = 0, srt;
  7.     printf("Number: ");
  8.     scanf("%d", &number);
  9.     srt = (int)sqrt(number) + 1; // корен квадратен
  10.     for (i = 2; i <= srt; i++)
  11.     {
  12.         if (number % i == 0)
  13.         {
  14.             n = 1;
  15.             break;
  16.         }
  17.     }
  18.  
  19.     if (n == 0)
  20.     {
  21.         printf("Number %d is prime.", number);
  22.     }
  23.     else
  24.     {
  25.         printf("Number %d is not prime.", number);
  26.     }
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement