Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ex_8_ASPNET_04_Array
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Declarando variaveis
- int[] iValoresX = new int[10];
- //Entrada de dados
- for (int i = 0; i < iValoresX.Length; i++) //.Lenght trás o comprimento do array
- {
- Console.Write("Digite o {0}º valor de X: ", (i + 1));
- int iValidar = Convert.ToInt32(Console.ReadLine());
- if ((iValidar < 0) || (iValidar > 9)){
- Console.WriteLine("\nO número informado precisa estar entre os valores '0...9'!\n ");
- --i;
- }
- else
- {
- iValoresX[i] = iValidar;
- }
- }
- Console.WriteLine("\nDigite uma posição para P: ");
- int iValorP = Convert.ToInt32(Console.ReadLine());
- //Validação se existem valores de X iguais ao valor de P
- int j = 0;
- for (int i = 0; i < iValoresX.Length; i++)
- {
- if (i == (iValorP - 1))
- {
- Console.WriteLine("\nValor de 'X' na posição 'P', é: {0}", iValoresX[i]);
- }
- else
- {
- iValoresX[j] = iValoresX[i];
- j++;
- }
- }
- Console.WriteLine("\nLista de números 'X', sem o valor de 'P' fica:");
- for (j = 0; j+1 < iValoresX.Length; j++)
- {
- Console.WriteLine("{0}", iValoresX[j]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment