Advertisement
rdsedmundo

1.cs

Apr 19th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2.  
  3. public class Exercicio1
  4. {
  5.     public static void Main()
  6.     {
  7.         // lê toda a linha, e separa num array de Strings
  8.         String[] numeros = Console.ReadLine().Split(' ');
  9.        
  10.         // n = total de números lidos
  11.         int n = numeros.Length;
  12.  
  13.         // cria um vetor double de n posições
  14.         double[] arbusto = new double[n];
  15.        
  16.         for (int i = 0; i < n; i++)
  17.             // converte para cada posição do vetor, o número correspondente (estava em String)
  18.             arbusto[i] = double.Parse(numeros[i]);
  19.            
  20.         // percorre o arbusto a partir da segunda posição, até a penúltima
  21.         for (int i = 1; i < n - 1; i++) {
  22.             // calcula a média entre o anterior e o próximo
  23.             double media = (arbusto[i-1] + arbusto[i+1])/2;
  24.            
  25.             // se o tamanho do arbusto atual, for maior que a media, então seta ele para a media
  26.             if (arbusto[i] > media)
  27.                 arbusto[i] = media;
  28.         }
  29.        
  30.         // imprime o penúltimo arbusto
  31.         Console.WriteLine(arbusto[n - 2]);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement