JottaJames

EX_8 C#_ASPNET_04_ARRAY

Apr 28th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 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_8_ASPNET_04_Array
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Declarando variaveis
  14.             int[] iValoresX = new int[10];
  15.  
  16.             //Entrada de dados
  17.             for (int i = 0; i < iValoresX.Length; i++) //.Lenght trás o comprimento do array
  18.             {
  19.                 Console.Write("Digite o {0}º valor de X: ", (i + 1));
  20.                 int iValidar = Convert.ToInt32(Console.ReadLine());
  21.  
  22.                 if ((iValidar < 0) || (iValidar > 9)){
  23.                     Console.WriteLine("\nO número informado precisa estar entre os valores '0...9'!\n ");
  24.                     --i;
  25.                 }
  26.                 else
  27.                 {
  28.                     iValoresX[i] = iValidar;
  29.                 }
  30.             }
  31.  
  32.             Console.WriteLine("\nDigite uma posição para P: ");
  33.             int iValorP = Convert.ToInt32(Console.ReadLine());
  34.  
  35.             //Validação se existem valores de X iguais ao valor de P
  36.             int j = 0;
  37.             for (int i = 0; i < iValoresX.Length; i++)
  38.             {
  39.                 if (i == (iValorP - 1))
  40.                 {
  41.                     Console.WriteLine("\nValor de 'X' na posição 'P', é: {0}", iValoresX[i]);
  42.                 }
  43.                 else
  44.                 {
  45.                     iValoresX[j] = iValoresX[i];
  46.                     j++;
  47.                 }
  48.             }
  49.  
  50.             Console.WriteLine("\nLista de números 'X', sem o valor de 'P' fica:");
  51.             for (j = 0; j+1 < iValoresX.Length; j++)
  52.             {
  53.                 Console.WriteLine("{0}", iValoresX[j]);
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment