Advertisement
JottaJames

EX_6 C#_ASPNET_04_ARRAY

Apr 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 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_6_ASPNET_04_Array
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Declaracao de variaveis
  14.             int[] arrayA = new int[10];
  15.             Random random = new Random();
  16.             int iQtMaiores = 0;
  17.  
  18.             //Preenche array com numeros aleatórios
  19.             for (int i = 0; i < arrayA.Length; i++)
  20.             {
  21.                 arrayA[i] = random.Next(1, 26);
  22.                 Console.WriteLine("{0}", arrayA[i]);
  23.             }
  24.  
  25.             //Ler um valor para X
  26.             Console.WriteLine("\nDigite um valor para X: ");
  27.             int iX = Convert.ToInt32(Console.ReadLine());
  28.  
  29.             //Contar qtd elementos dentro do arrayA são maiores do que X
  30.             for (int i = 0; i < arrayA.Length; i++)
  31.             {
  32.                 if (arrayA[i] > iX)
  33.                 {
  34.                     iQtMaiores++;
  35.                 }
  36.             }
  37.  
  38.             //Criando o Array S
  39.             int[] arrayS = new int[iQtMaiores];
  40.  
  41.             int j = 0;
  42.             //Copiar para o arrayS os valores do arrayA > X
  43.             for (int i = 0; i < arrayA.Length; i++)
  44.             {
  45.                 if (arrayA[i] > iX)
  46.                 {
  47.                     arrayS[j] = arrayA[i];
  48.                     j++;
  49.                 }
  50.             }
  51.  
  52.             Console.WriteLine("\n");
  53.             //Imprime arrayS
  54.             for (int i = 0; i < arrayS.Length; i++)
  55.             {
  56.                 Console.WriteLine("{0}", arrayS[i]);
  57.             }
  58.  
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement