Advertisement
jusapi

ConceptosArrays

Aug 18th, 2022
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 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 Arrays01
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // Definición vector
  14.             int[] arrayNumeros; // Definición del Array
  15.             arrayNumeros = new int[5]; // Inicialización array
  16.  
  17.             // Asignación de valores al Array
  18.             arrayNumeros[0] = 20;
  19.             arrayNumeros[1] = 40;
  20.             arrayNumeros[2] = 60;
  21.             arrayNumeros[3] = 80;
  22.             arrayNumeros[4] = 10;
  23.  
  24.             // Mostrar elementos del Array
  25.             Console.WriteLine("Valor pos 0: "+arrayNumeros[0]);
  26.             Console.WriteLine("Valor pos 2: " + arrayNumeros[2]);
  27.             Console.WriteLine("Valor pos 4: " + arrayNumeros[4]);
  28.  
  29.             arrayNumeros[2] = 300;
  30.             Console.WriteLine("Nuevo valor pos 2: " + arrayNumeros[2]);
  31.             Console.WriteLine("--------------------------");
  32.  
  33.             //Definición/Inicialización array valores fijos
  34.             double[] arrayPesos = { 50.4, 70, 80.5 };
  35.             // Mostrar elementos del Array
  36.             Console.WriteLine("Valor pos 0: " + arrayPesos[0]);
  37.             Console.WriteLine("Valor pos 1: " + arrayPesos[1]);
  38.             Console.WriteLine("Valor pos 2: " + arrayPesos[2]);
  39.             /*************************************************/
  40.             Console.WriteLine("--------------------------");
  41.             // Visualización todos los valores del array
  42.             for (byte i=0; i < arrayPesos.Length; i++)
  43.             {
  44.                 Console.WriteLine("Array pos: {0} es: {1}",i,arrayPesos[i]);
  45.             }
  46.  
  47.             /*************************************************/
  48.             double[] arrayPromedioNotas;
  49.             Console.WriteLine("Ingrese la cantidad de estudiantes");
  50.             _ = int.TryParse(Console.ReadLine(), out int cantNotas);
  51.  
  52.             // Definir array según tamaño ingresado por usuario
  53.             arrayPromedioNotas = new double[cantNotas];
  54.  
  55.             // LLenar los elementos del array
  56.             for (byte i=0; i < arrayPromedioNotas.Length; i++)
  57.             {
  58.                 Console.WriteLine("Cual es el promedio del estudiante {0}",(i+1));
  59.                 arrayPromedioNotas[i] = double.Parse(Console.ReadLine());
  60.                 //_ = double.TryParse(Console.ReadLine(), out arrayPromedioNotas[i]);
  61.             }
  62.  
  63.             // VIsualizar elementos del array
  64.             for (byte i=0; i < arrayPromedioNotas.Length; i++)
  65.             {
  66.                 Console.WriteLine("EL promedio del estudiante {0} es: {1}",(i+1), arrayPromedioNotas[i]);
  67.             }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.             Console.ReadKey();
  77.         }
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement