Advertisement
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_6_ASPNET_04_Array
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Declaracao de variaveis
- int[] arrayA = new int[10];
- Random random = new Random();
- int iQtMaiores = 0;
- //Preenche array com numeros aleatórios
- for (int i = 0; i < arrayA.Length; i++)
- {
- arrayA[i] = random.Next(1, 26);
- Console.WriteLine("{0}", arrayA[i]);
- }
- //Ler um valor para X
- Console.WriteLine("\nDigite um valor para X: ");
- int iX = Convert.ToInt32(Console.ReadLine());
- //Contar qtd elementos dentro do arrayA são maiores do que X
- for (int i = 0; i < arrayA.Length; i++)
- {
- if (arrayA[i] > iX)
- {
- iQtMaiores++;
- }
- }
- //Criando o Array S
- int[] arrayS = new int[iQtMaiores];
- int j = 0;
- //Copiar para o arrayS os valores do arrayA > X
- for (int i = 0; i < arrayA.Length; i++)
- {
- if (arrayA[i] > iX)
- {
- arrayS[j] = arrayA[i];
- j++;
- }
- }
- Console.WriteLine("\n");
- //Imprime arrayS
- for (int i = 0; i < arrayS.Length; i++)
- {
- Console.WriteLine("{0}", arrayS[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement