Advertisement
it4l0

planeta

Dec 4th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5.     int x = 0, z = 0, t = 0, aux = 0;
  6.     double tempo[100]; double aux1 = 0; double maior;
  7.     scanf("%d", &x);
  8.     for (t = 0; t < x; ++t)
  9.     {
  10.         scanf("%lf", &tempo[t]);
  11.     }
  12.     //ordenacao de array
  13.     for (t = 0; t < x; ++t)
  14.     {
  15.         aux = t;
  16.         for (z = t + 1; z < x; ++z)
  17.         {
  18.             if(tempo[z] > tempo[aux])
  19.             {
  20.                 aux = z;
  21.             }
  22.         }
  23.         aux1 = tempo[t];
  24.         tempo[t] = tempo[aux];
  25.         tempo[aux] = aux1;
  26.     }
  27.     //fim ordenacao
  28.     maior = tempo[0];
  29.     int cont = x - 1, contador = 0; double maior1 = 0;
  30.     maior1 = maior;
  31.     while(cont > 0)
  32.     {
  33.         for(t = 1; t < x; ++t)
  34.         {
  35.             if(tempo[t] == 0)
  36.             {
  37.                 printf("SEM RESPOSTA");
  38.             }
  39.             else if(fmod(maior1, tempo[t]) == 0)
  40.             {
  41.                 contador++;
  42.             }
  43.         }
  44.         if(contador == cont)
  45.         {
  46.             printf("O tempo para o alinhamento dos planetas e %.1lf minutos", maior1);
  47.             return 0; cont = -1;
  48.         } else{
  49.             maior1 += maior;
  50.             t = 1; contador = 0;
  51.         }
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement