Advertisement
mantertius

primo.c

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