AnandaVieira

Exercício18

Apr 21st, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Exercício
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             /* 18. Escreva um programa para ler dois valores o primeiro indica o tipo de temperatura (C - Celsius ou F - Fahrenheit) e
  10.             o segundo a temperatura. Faça o cálculo realizando as conversões entre as temperaturas:
  11.             a) Celsius para Fahrenheit: F = (9 / 5) * ºC + 32
  12.             b) Fahrenheit para Celsius: C = (ºF − 32) / 1.8 */
  13.  
  14.             Console.Write("Escolha a temperatura [C] - Celsius ou [F] - Fahrenheit: ");
  15.             string op = Console.ReadLine();
  16.  
  17.             Console.Write("Digite a temperatura: ");
  18.             double temp = double.Parse(Console.ReadLine());
  19.  
  20.             if (op == "F")
  21.             {
  22.                 double fah = (9 / 5) * temp + 32;
  23.                 Console.WriteLine("Temperatura: " + fah.ToString("F2") + "ºF");
  24.             }
  25.             else if (op == "C")
  26.             {
  27.                 double cel = (temp - 32) / 1.8;
  28.                 Console.WriteLine("Temperatura: " + cel.ToString("F2") + "ºC");
  29.             }
  30.  
  31.  
  32.         }
  33.  
  34.     }
  35. }
  36.  
Add Comment
Please, Sign In to add comment