Tecnico En Informatica
estructura de datos
que se usa para almacenar cualquier clase de datos, incluyendo enteros,flotantes, caracteres, arreglos,apuntadores, y registros
(
structs
)
Además, los arreglos son tanversátiles que se pueden usar para implementar otras estructuras de datos, como pilas, colas,listas ligadas y árboles binarios, de hecho en algunos lenguajes corno
FORTRAN
, el arreglo es laúnica estructura de datos disponible para el programador, porque, por medio del uso de arregloses posible implementar la mayor parte deotras estructuras.
ejercicio 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
string[] nombre=new string [5];
int op;
do
{
Console.Clear();
Console.WriteLine("[1]Ingresar Nombre: ");Console.WriteLine("[2]Mostrar Nombres: ");
Console.WriteLine("[3]Salir ");
Console.WriteLine("Elija Opcion ");
op = Int32.Parse(Console.ReadLine());
switch (op)
{
case 1:
for (int i = 0; i <= 4; i++)
{
Console.Clear();
Console.WriteLine("Ingrese Nombre: ");
nombre[i] = Console.ReadLine();
} Console.ReadLine(); break;
case 2:
Console.Clear();
for (int i = 0; i <= 4; i++)
{Console.WriteLine(nombre[i]);
} Console.ReadLine(); break;
}
} while (op <= 2);
}
}
}
Ejemplo 2 :
Dada la matriz A :
8
9
5
6
3
2
y la matriz B :
7
1
4
5
0
3
Elaborar un programa en C# para obtener la suma de ambas matrices: S = A + B
// SumMatrices.cs : Suma dos matrices de 2 renglones y 3 columnas.
using System;
using C = System.Console;
namespaceSumatrices
{
class Matriz
{
public static void Main()
{
const int r = 2, c = 3;
int i, j;
double[,] A = new double[r, c];
double[,] B = new double[r, c];
double[,] S = new double[r, c];
C.Clear();
// Lectura de valores para los elementos de A.
C.WriteLine("Suma de las matrices A y B de 2x3\n");
C.WriteLine("\nTeclee los valores de la Matriz A\n");
for (i = 0; i < r;i++)
for (j = 0; j < c; j++)
{
C.Write(" A[{0},{1}] = ",i,j);
A[i, j] = Double.Parse(Console.ReadLine());
}
// Lectura de valores para los elementos de B.
C.WriteLine("\nTeclee los valores de la Matriz B\n");
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
{
C.Write(" B[{0},{1}] = ", i,j);
B[i, j] = Double.Parse(Console.ReadLine());
}
// Suma y desplieguede la matriz resultado.
C.WriteLine("\nMatriz S = A+B\n");
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
S[i, j] = A[i, j] + B[i, j];
C.Write(" " + S[i, j]);
}
C.WriteLine();
}
}
}
}
{
Console.WriteLine(nombre[i]);
} Console.ReadLine(); break;
}
} while (op <= 2);
}
}
}
ejercicio 3
using System;
public classArregloDosDimensiones
{
static void Main()
{
// declaracion e iniciaci&oacute;n de arreglos rectangulares
int[,] arreglo1 = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };
// declaraci&oacute;n e iniciaci&oacute;n de arreglos dinamicos
int[][] arreglo2 = new int[3][];
string salida = "";
arreglo2[0] = new int[] { 1, 2};
arreglo2[1] = new int[] { 3 };
arreglo2[2] = new int[] { 4, 5, 6 };
salida = "Valores en arreglo1 por fila\n";
// salida del arreglo1
for (int i = 0; i < arreglo1.GetLength(0); i++)
{
for (int j = 0; j < arreglo1.GetLength(1); j++)
salida += arreglo1[i, j] + " ";
salida += "\n";
}...
Regístrate para leer el documento completo.