Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6.  
  7. int main() {
  8.  
  9.     double m;
  10.     int n,i;
  11.     printf("Podaj liczbe naturalna: ");
  12.     scanf("%d", &n);
  13.     if (n < 0)
  14.     {
  15.         printf("Podales zla liczbe");
  16.         return 0;
  17.     }
  18.     m = sqrt(n);
  19.     i = 3;
  20.     if (n != 2 && n % 2 == 0 || n < 2)
  21.         i = n;
  22.  
  23.     while (i < m)
  24.     {
  25.         if (n % i == 0)
  26.         {
  27.             i = n;
  28.         }
  29.         else
  30.         {
  31.             i += 2;
  32.         }
  33.     }
  34.  
  35.     if (i == n)
  36.     {
  37.         printf("%d nie jest liczba pierwsza", n);
  38.     }
  39.     else {
  40.         printf("%d nie jest liczba pierwsza", n);
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement