Advertisement
JottaJames

EX_4 C#_ASPNET_04_ARRAY

Apr 21st, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Ex_4_ASPNET_04_Array
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Declarando variaveis
  14.             int[] iValoresA = new int[10];
  15.             string sPosição = "";
  16.  
  17.             //Entrada de dados
  18.             for (int i = 0; i < iValoresA.Length; i++) //.Lenght trás o comprimento do array
  19.             {
  20.                 Console.Write("Digite o {0}º valor de A: ", (i + 1));
  21.                 iValoresA[i] = Convert.ToInt32(Console.ReadLine());
  22.             }
  23.  
  24.             Console.WriteLine("\nDigite um valor para X: ");
  25.             int iValorX = Convert.ToInt32(Console.ReadLine());
  26.  
  27.             //Validação se existem valores de A iguais ao valor de X
  28.             for (int j = 0; j < iValoresA.Length; j++)
  29.             {
  30.                 if (iValoresA[j] == iValorX)
  31.                 {
  32.                     if (sPosição != "")
  33.                     {
  34.                         sPosição = String.Concat(sPosição, " | ", (j+1), "º");
  35.                     }
  36.                     else
  37.                     {
  38.                         sPosição = String.Concat("\nDentre os 10 numeros digitados para 'A', nas seguintes posições" +
  39.                             " existem os mesmos valores que o informado para 'X': \n", (j+1), "º");
  40.                     }
  41.                 }
  42.             }
  43.  
  44.             //Saída dos dados
  45.             if(sPosição == "")
  46.             {
  47.                 Console.WriteLine("\nNenhum dos números digitados para 'A' foi o mesmo que o digitado para 'X'!");
  48.             }
  49.             else
  50.             {
  51.                 Console.WriteLine("{0}", sPosição);
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement