Sie sind auf Seite 1von 3

CLASE: ARRAY UNIDIMENCIONAL Y BIDIMENCIONAL

using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication20 { class Program { static void Main(string[] args) { //hacer un programa para ingresar 5 numeros enteros a un array y mostrarlos int[] NUMEROS;// DE ESTA MANERA SE DECLARA A UN ARRAY UNIMENCIONAL, SE TRABAJO CON PASICIONES int[][] NUMERO1;//DE ESTA MANERA SE DECLARA A UN ARRAY BIDIMENCIONAL (MATRICES), SE TRABAJO CON PASICIONES int x, n; Console.WriteLine("ingrese cuantos numero"); n=int.Parse(Console.ReadLine()); NUMEROS = new int[n];// siempre debe de exitir y ralacionado con: int [] NUMERO. El n es la cantidad de numeros que se decea ingresar y x nuestra la posicion. for (x = 0; x < n; x++)//este for es para ingresar { Console.WriteLine("ingrese numero en la posicion {0}", x); NUMEROS[x] = int.Parse(Console.ReadLine()); } Console.WriteLine("los numeros son:"); for (x = 0; x < n; x++)// para visualizar la lista o mostrar { Console.WriteLine("el numero en la posicion {0}es {1}" ,x,NUMEROS[x]); } } } }

PARA IMPRIMIR LA POSICION DECEADA:


using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication20 { class Program { static void Main(string[] args) { //hacer un programa para ingresar 5 numeros enteros a un array y mostrarlos int[] NUMEROS;// DE ESTA MANERA SE DECLARA A UN ARRAY UNIMENCIONAL, SE TRABAJO CON PASICIONES int[][] NUMERO1;//DE ESTA MANERA SE DECLARA A UN ARRAY BIDIMENCIONAL (MATRICES), SE TRABAJO CON PASICIONES int x, n,y; Console.WriteLine("ingrese cuantos numero: "); n=int.Parse(Console.ReadLine()); NUMEROS = new int[n];// siempre debe de exitir y ralacionado con: int [] NUMERO. El n es la cantidad de numeros que se decea ingresar y x nuestra la posicion.

for (x = 0; x < n; x++)//este for es oara ingresar { Console.WriteLine("ingrese numero en la posicion {0}: ", x); NUMEROS[x] = int.Parse(Console.ReadLine()); } Console.WriteLine("ingrese la posicion del numero: "); y = int.Parse(Console.ReadLine()); Console.WriteLine("el numero de la posicion {0}es {1}", y, NUMEROS[y]); } } }

PARA IMPRIMIR INVERTIDO LA LISTA: Solo se modifica :


for (x = n-1; x >=0; x--)// para visualizar la lista o mostrar { Console.WriteLine("el numero en la posicion {0}es {1}", x, NUMEROS[x]); }

HACER UN PROGRAMA, QUE SE INGRESE 5 NUMEROS Y QUE NUESTRE LOS NUMEROS PARES
using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication20 { class Program { static void Main(string[] args) { //hacer un programa para ingresar 5 numeros enteros a un array y mostrarlos int[] NUMEROS;// DE ESTA MANERA SE DECLARA A UN ARRAY UNIMENCIONAL, SE TRABAJO CON PASICIONES int[] NUMEROpares;//DE ESTA MANERA SE DECLARA A UN ARRAY BIDIMENCIONAL (MATRICES), SE TRABAJO CON PASICIONES int x; NUMEROS = new int[5];// siempre debe de exitir y ralacionado con: int [] NUMERO. El n es la cantidad de numeros que se decea ingresar y x nuestra la posicion. NUMEROpares = new int[5];//siempre debe de exitir y ralacionado con: int [] NUMEROpares. for (x = 0; x < 5; x++)//este for es para ingresar { NUMEROS[x] = int.Parse(Console.ReadLine()); } for (x = 0; x <5; x++)// para visualizar la lista o mostrar { if(NUMEROS[x]%2==0) { NUMEROpares[x] = NUMEROS[x]; } } Console.WriteLine("LOS NUMEROS PARES SON");

for(x=0;x<5;x++) { Console.WriteLine("{0}",NUMEROpares[x]); } } } } Para que imprima solo los numeros y no los ceros se debe cambiar en el ultimo for: if (NUMEROpares[x] != 0) { Console.WriteLine("{0}", NUMEROpares[x]); } Por el : Console.WriteLine("{0}",NUMEROpares[x]);

Das könnte Ihnen auch gefallen