using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SumarArray
{ class SumarArray
{ private int[] ArrayA;//Declaramos el array A
private int[] ArrayB;//Declaramos el array B
private int[] ArrayC;//Declaramos el array C
public void Cargar()
{ Console.Write("\nIngrese la longitud de los arrays a sumar: "); string linea;
linea = Console.ReadLine();
int n = int.Parse(linea);
ArrayA = new int[n];
ArrayB = new int[n];
ArrayC = new int[n];
Console.WriteLine("\nIngresando valores del array A"); for (int i = 0; i < ArrayA.Length; i++)
{ Console.Write("Ingrese valor al elemento [" + ( i + 1 ) +"]: "); linea = Console.ReadLine();
ArrayA[i] = int.Parse(linea);
}
Console.WriteLine("\nIngresando valores del array B"); for (int i = 0; i < ArrayB.Length; i++)
{ Console.Write("Ingrese valor al elemento [" + (i + 1) + "]: "); linea = Console.ReadLine();
ArrayB[i] = int.Parse(linea);
}
//Sumamos el array A con el array B
for (int i = 0; i< ArrayC.Length; i++)
{ ArrayC[i]=ArrayA[i] + ArrayB[i];
}
}
public void Visualizar()
{ Console.WriteLine("\n\nLa suma de los arrays es: "); for (int i = 0; i< ArrayC.Length; i++)
{ Console.Write("["+i+"] "+ArrayC[i]+"\n"); }
Console.ReadLine();
}
static void Main(string[] args)
{ SumarArray pv = new SumarArray();
pv.Cargar();
pv.Visualizar();
}
}
}
Comentarios sobre la versión: 1 (1)