Advertisement
Hardware

Conversor de Temperatura - Celsius,Kelvin e Fahrenheit

Nov 6th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. main()
  5. {
  6.       int op,i;
  7.       float cel[2],fah[2],kel[2],Result[6];
  8.      
  9.      for(i=0; op != 0; i++)
  10.      {     
  11.            printf("\n-> ~~~~~~~~~~~~~~~~ Conversor de Temperatura ~~~~~~~~~~~~~~~~~ <-\n");
  12.            printf("\n");
  13.            printf("1 - Celsius para Fahrenheit\n");
  14.            printf("2 - Celsius para Kelvin\n");
  15.            printf("\n");
  16.            printf("3 - Fahrenheit para Celsius\n");
  17.            printf("4 - Fahrenheit para Kelvin\n");
  18.            printf("\n");
  19.            printf("5 - Kelvin para Celsius\n");
  20.            printf("6 - Kelvin para Fahrenheit\n");
  21.            printf("\n");
  22.            printf("0 - Para sair\n");
  23.            printf("Escolha qual das conversoes desejas fazer:");
  24.            scanf("%d",&op);
  25.            system("CLS");
  26.            if(op > 6)
  27.            {
  28.                  printf("(ERRO) Numero invalido!");
  29.            }
  30.            switch(op)
  31.            {
  32.                      system("CLS");
  33.                      case 1:
  34.                      {
  35.                           printf("Digite o numero de graus Celsius:");
  36.                           scanf("%f",&cel[0]);
  37.                           Result[0] = ((cel[0] *1.8) + 32);
  38.                           printf("Resultado: %0.3f graus Fahrenheit\n",Result[0]);
  39.                           break;
  40.                      }
  41.                      case 2:
  42.                      {
  43.                           printf("Digite o numero de graus Celsius:");
  44.                           scanf("%f",&cel[1]);
  45.                           Result[1] = cel[1] + 273.15;
  46.                           printf("Resultado: %0.3f Kelvin",Result[1]);
  47.                           break;
  48.                      }
  49.                      case 3:
  50.                      {
  51.                           printf("Digite um numero de graus Fahrenheit:");
  52.                           scanf("%f",&fah[0]);
  53.                           Result[2] = (fah[0] - 32) / 1.8;
  54.                           printf("Resultado: %0.3f Celsius",Result[2]);
  55.                           break;
  56.                      }
  57.                      case 4:
  58.                      {
  59.                           printf("Digite um numero de graus Fahrenheit:");
  60.                           scanf("%f",&fah[1]);
  61.                           Result[3] = ((fah[1] + 459.67) / 1.8);
  62.                           printf("Resultado: %0.3f Kelvin",Result[3]);
  63.                           break;
  64.                      }
  65.                      case 5:
  66.                      {
  67.                           printf("Digite um numero na escala Kelvin:");
  68.                           scanf("%f",&kel[0]);
  69.                           Result[4] = kel[0] - 273.15;
  70.                           printf("Resultado: %0.3f graus Celsius",Result[4]);
  71.                           break;
  72.                      }
  73.                      case 6:
  74.                      {
  75.                           printf("Digite um numero na escala Kelvin:");
  76.                           scanf("%f",&kel[1]);
  77.                           Result[5] = ((kel[1] * 1.8) - 459.67);
  78.                           printf("Resultado: %0.3f Fahrenheit.",Result[5]);
  79.                           break;
  80.                      }
  81.                }        
  82.          }
  83.    }
  84.                                      
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement