AnandaVieira

Exercicio 62

May 12th, 2021 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ScriptCSharp
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             /*Exercício 62
  11.             Elabore um programa que faça leitura de vários números inteiros, até que se digite um
  12.             número negativo.
  13.             O programa tem que retornar o maior e o menor número lido.*/
  14.  
  15.             int maior, menor, num;
  16.  
  17.             maior = 0;
  18.             menor = 1000;
  19.  
  20.             do
  21.             {
  22.                 Console.WriteLine("Digite um número: ");
  23.                 num = int.Parse(Console.ReadLine());
  24.  
  25.                 if (num > 0)
  26.                 {
  27.                     if (num > maior)
  28.                     {
  29.                         maior = num;
  30.                     }
  31.                     if (num < menor)
  32.                     {
  33.                         menor = num;
  34.                     }
  35.                 }
  36.             } while (num > 0);
  37.  
  38.             Console.WriteLine("O maior número: " + maior);
  39.             Console.WriteLine("O menor número: " + menor);
  40.  
  41.  
  42.             }
  43.  
  44.     }
  45.  
  46. }
Add Comment
Please, Sign In to add comment