Advertisement
InnadrilCastle

prvocislo

Apr 21st, 2020
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int delime(int delitel, int delenec) {
  5.         if((delenec%delitel) == 0)
  6.                 return 1;
  7.         else
  8.                 return 0;
  9. }
  10.  
  11. int main(void)
  12. {
  13.         int cislo, exitStatus, kurzor;
  14.         float odmocnina;
  15.  
  16.         printf("Enter your integer: ");
  17.         exitStatus = scanf("%d", &cislo);
  18.  
  19.         if(exitStatus == 1) {
  20.                 if (cislo <= 0) {
  21.                         printf("It seems you have entered too big number!\n");
  22.                         return 1;
  23.                 }
  24.         }
  25.         else {
  26.                 printf("You should enter number!\n");
  27.                 return 1;
  28.         }
  29.  
  30.         if (cislo == 1) {
  31.                 printf("1 is not prime number.\n");
  32.                 return 0;
  33.         }
  34.  
  35.         if (cislo == 2) {
  36.                 printf("2 is prime number.\n");
  37.                 return 0;
  38.                 }
  39.  
  40.         if(delime(2, cislo)) {
  41.                 printf("%d is not prime number!\n", cislo);
  42.                 return 0;
  43.         }
  44.  
  45.         odmocnina = sqrtf(cislo);
  46.         kurzor = 3;
  47.         while(kurzor <= odmocnina) {
  48.                 if(delime(kurzor, cislo)) {
  49.                         printf("%d is not prime number!\n", cislo);
  50.                         return 0;
  51.                 }
  52.                 kurzor = kurzor + 2;
  53.         }
  54.          printf("%d is prime number!\n", cislo);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement