Advertisement
mantertius

primo.c

Nov 26th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. //https://thehuxley.com/problem/972
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int verificaPRIMO(int x, int y) //verifica se um numero é primo
  6. {
  7.     if (x%y == 0 && y==1)
  8.     {
  9.         return 1;
  10.     }
  11.     else if (x%y == 0 && y != 1)
  12.     {
  13.         return 0;
  14.     }
  15.     else
  16.     {
  17.         return verificaPRIMO(x,--y);
  18.     }
  19.    
  20. }
  21. void scan()
  22. {
  23.     int x;
  24.     scanf("%d",&x);
  25.     if (x == -1)
  26.     {
  27.         return;
  28.     }
  29.     else
  30.     {
  31.         printf("%d\n",verificaPRIMO(x,x));
  32.         scan();
  33.     }
  34. }
  35.  
  36. int main ()
  37. {
  38.     int numero_base;
  39.     scanf("%d",&numero_base);
  40.     if (numero_base == -1) //finalizar o programa se input == -1
  41.     {
  42.         return 0;
  43.     }
  44.     else
  45.     {
  46.         printf("%d\n",verificaPRIMO(numero_base,numero_base));
  47.         scan();
  48.     }
  49. }
  50.  
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement