Você está na página 1de 36

1.

HACER UN PROGRAMA PARA INGRESAR NOMBRES


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication70 { class Program { static void Main(string[] args) {

Determinar nmero de elementos de la matriz

Ingresar los nombres del arreglo

int num; Console.WriteLine("Cuantos nombres desea ingresar: "); Declaracin num=int.Parse(Console.ReadLine()); de matriz string[] nombres; nombres=new string[num]; int i; Crear matriz para que posteriormente nombres[ for (i = 0; i < num; i++) i ] trabaje como si fuera una variable cualquiera { Console.WriteLine("Nombre de la posicion {0}",i); nombres[i] = Console.ReadLine(); Declaracin
de subndice

} Console.WriteLine(); Console.WriteLine("Los nombres ingresados son"); Console.WriteLine(); for (i = 0; i < num; i++) { Console.WriteLine("Nombre de la posicion {0} es {1} ",i,nombres[i]); } } } }

Mostrar los datos

2.HACER UNA BUSQUEDA PARA CAMBIAR UN NOMBRE POR EJEMPLO JUAN POR PAUL
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication75 { class Program { static void Main(string[] args) { int num; Console.WriteLine("Cuanto nombres desea ingresar: num=int.Parse(Console.ReadLine());

");

string[] nombres; nombres= new string[num]; int i; for(i=0;i<num;i++) { Console.WriteLine("Ingrese nombres {0}",i); nombres[i]=Console.ReadLine(); } Console.WriteLine(); Console.WriteLine("Los nombres ingresados son:"); for(i=0;i<num;i++) { Console.WriteLine("Los nombres ingresados en la posicion {0} es {1}", i, nombres[i]); } Console.WriteLine("Modificacion de datos"); string nomcam; Console.WriteLine("Ingrese nombre a reemplazar"); nomcam = Console.ReadLine(); for(i=0;i<num;i++) if (nomcam == nombres[i]) { Console.WriteLine("Ingrese nombre nuevo"); nombres [i] = Console.ReadLine(); } for (i = 0; i < num; i++) { Console.WriteLine("Nombre en la posicion {0} es {1}",i,nombres[i]); } } } }
Mostrar los datos Ingresar los nombres del arreglo

Declarar variable que modificara Modificacin de dato

Mostrar modificacin

2.a HACER UNA BUSQUEDA PARA CAMBIAR UN NUMERO POR OTRO


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication133 { class Program { static void Main(string[] args) { int num; Console.WriteLine("Cuanto numeros desea ingresar: num = int.Parse(Console.ReadLine());

");

int[] numeros; numeros = new int[num]; int i; for (i = 0; i < num; i++) { Console.WriteLine("Ingrese numeros {0}", i); numeros[i] = int.Parse(Console.ReadLine()); } Console.WriteLine(); Console.WriteLine("Los numeros ingresados son:"); for (i = 0; i < num; i++) { Console.WriteLine("Los numeros ingresados en la posicion {0} es {1}", i, numeros[i]); } Console.WriteLine("Modificacion de datos"); int numcam; Console.WriteLine("Ingrese numero a reemplazar"); numcam = int.Parse(Console.ReadLine()); for (i = 0; i < num; i++) if (numcam == numeros[i]) { Console.WriteLine("Ingrese numero nuevo"); numeros[i] =int.Parse(Console.ReadLine()); } for (i = 0; i < num; i++) { Console.WriteLine("Numeros en la posicion {0} es {1}", i, numeros[i]); } } } }

2b.mostrar una matriz unidimensional cualquiera


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication151 { class Program { static void Main(string[] args) { int num; Console.WriteLine("Cuanto numeros desea ingresar:

");

num = int.Parse(Console.ReadLine()); int[] numeros; numeros = new int[num]; int i; for (i = 0; i < num; i++) { Console.WriteLine("Ingrese numeros {0}", i); numeros[i] = int.Parse(Console.ReadLine()); } Console.WriteLine(); Console.WriteLine("Los numeros ingresados son:"); for (i = 0; i < num; i++) { Console.WriteLine("Los numeros ingresados en la posicion {0} es {1}", i, numeros[i]); } } } }

3.ESCRIBIR NOMBRES EN FORMA ASCENDENTE Y MOSTRAR EN FORMA DESCENDENTE


namespace ConsoleApplication42 { class Program { static void Main(string[] args) { string[] nombresas; string[] nombresds; int num; Console.WriteLine("Cuantos nombres desea ingresar"); num = int.Parse(Console.ReadLine()); nombresas = new string[num]; nombresds = new string[num]; for (int i = 0; i<num; i = i + 1) { Console.WriteLine("ingrese nombre en la posicion {0}", i); nombresas[i] = Console.ReadLine(); } int x = num-1; for (int i = 0; i<num; i = i + 1)

} for (int i=0 ;

nombresds[x]=nombresas[i]; x=x-1; i<num ; i = i + 1) son {0}",nombresds[i]);

{ Console.WriteLine("Los datos }

} }

4.ESCRIBIR NOMBRES Y SUS RESPECTIVAS EDADES


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication41 { class Program { static void Main(string[] args) { string[] nombres; int[] edad; int num; Console.WriteLine("Cuantos nombres desea ingresar"); num = int.Parse(Console.ReadLine()); nombres = new string[num]; edad = new int [num]; for (int i = 0; i < num; i++) { Console.WriteLine("ingrese nombre en la posicion {0}",i); nombres [i]= Console.ReadLine(); Console.WriteLine("ingrese edad {0}", i); edad [i] =int.Parse ( Console.ReadLine());

} Console.WriteLine(); Console.WriteLine("Los nombres ingresados son: "); Console.WriteLine("********************************"); Console.WriteLine();

for (int i = 0; i < num; i++) { Console.WriteLine("Nombre de la posicin {0} es {1}y tiene {2}aos ",i,nombres[i],edad[i]); } Console.ReadLine(); } } }

5.ESCRIBIR NOMBRES Y DOS NOTAS RESPECTIVAS A CADA NOMBRE.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication41 { class Program { static void Main(string[] args) { string[] nombres; int[] edad; int num; int[] nota1; int[] nota2; Console.WriteLine("Cuantos nombres desea ingresar"); num = int.Parse(Console.ReadLine()); nombres = new string[num]; edad = new int [num]; nota1 = new int [num]; nota2 = new int [num]; for (int i = 0; i < num; i++) { Console.WriteLine("ingrese nombre en la posicion {0}",i); nombres [i]= Console.ReadLine(); Console.WriteLine("ingrese edad {0}", i); edad [i] =int.Parse ( Console.ReadLine()); Console.WriteLine("ingrese nota1 {0}", i); nota1[i] =int.Parse ( Console.ReadLine()); Console.WriteLine("ingrese nota2 {0}", i); nota2[i] = int.Parse(Console.ReadLine()); } Console.WriteLine();

Console.WriteLine("Los nombres ingresados son: "); Console.WriteLine("********************************"); Console.WriteLine(); for (int i = 0; i < num; i++) { Console.WriteLine("Nombre de la posicin {0} es {1}y tiene {2}aos y su promedio es {3} ",i,nombres[i],edad[i],((nota1[i] +nota2[i])/2)); } Console.ReadLine();

} } }

6.EJERCICIO QUE PERMITE ORDENAR ASCENDENTEMENTE UNA CANTIDAD DE NUMEROS.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication106 { class Program { static void Main(string[] args) { int x, y, cant, auxiliar; Console.WriteLine("Cuantos numeros va ha ingresar"); cant = int.Parse(Console.ReadLine()); int[] numero; numero = new int[cant + 1]; for (x = 1; x <= cant; x++) { Console.WriteLine("Ingrese el numero {0}", x); numero[x] = int.Parse(Console.ReadLine()); } //mtodo burbuja para ordenar los numeros ingresados. for (x = 1; x <= cant - 1; x++) { for (y = 1; y <= cant - x; y++) { if (numero[y] > numero[y + 1]) { auxiliar = numero[y]; numero[y] = numero[y + 1]; numero[y + 1] = auxiliar;

} } } Console.WriteLine("Nmeros ordenados ascendentemente son: "); for (x = 1; x <= (cant); x++) { Console.WriteLine("{0}", numero[x]); } } } }

7.PROGRAMA QUE MUESTRA LOS NUMEROS ORDENADOS ASCENDENTEMENTE Y LOS DESORDENADOS.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication103 { class Program { static void Main(string[] args) { int x, y, cant, auxiliar; Console.WriteLine("Cuantos numeros va ha ingresar"); cant = int.Parse(Console.ReadLine()); int[] numero; int[] desorden; numero=new int[cant+1]; desorden = new int[cant + 1]; for (x = 1; x <= cant; x++) { Console.WriteLine("Ingrese el numero {0}",x); numero[x]=int.Parse(Console.ReadLine()); desorden[x] = numero[x]; } //mtodo burbuja para ordenar los numeros ingresados. for (x = 1; x <= cant - 1; x++) { for (y = 1; y <= cant - x; y++) { if (numero[y] > numero[y + 1])

{ auxiliar = numero[y]; numero[y]=numero[y+1]; numero[y + 1] = auxiliar; } } } Console.WriteLine("Nmeros ordenados ascendentemente son: "); for (x = 1; x <= (cant); x++) { Console.WriteLine("{0}\t\t\t\t\t\t{1}", numero[x], desorden[x]); } } } }

8.MAYOR ELEMENTO DE UNA MATRIZ UNIDIMENSIONAL.


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

namespace ConsoleApplication77 { class Program { static void Main(string[] args) {

int[] numero;

int x, y, cant, auxiliar;

Console.WriteLine("Cuantos numeros va a ingresar");

cant = int.Parse(Console.ReadLine()); numero = new int[cant + 1]; for (x = 1; x <= cant; x++) { Console.WriteLine("Ingrese el numero {0}", x); numero[x] = int.Parse(Console.ReadLine()); } //mtodo burbuja para ordenar los numeros ingresados. for (x = 1; x <= cant-1; x++) { for (y = 1; y <= (cant - x); y++) { if (numero[y] > numero[y + 1]) { auxiliar = numero[y]; numero[y] = numero[y + 1]; numero[y + 1] = auxiliar; } } }

Console.WriteLine("LOS NUMEROS ORDENADOS ASCENDENTEMENTE SON :"); for (x = 1; x <= (cant); x++) { Console.WriteLine("{0}", numero[x]);

Console.WriteLine("EL MAYOR ES :"); for (x = 1; x <= (cant); x++) { Console.WriteLine("{0}", numero[x=cant]);

} } }

9.PROGRAMA QUE MUESTRA LOS NUMEROS ORDENADOS DESCENDENTEMENTE Y MUESTRE EL NUMERO MENOR Y MAYOR.
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication105 { class Program { static void Main(string[] args) { int x, y, cant, auxiliar; Console.WriteLine("Cuantos numeros va ha ingresar"); cant = int.Parse(Console.ReadLine()); int[] numero; int[] desorden; numero = new int[cant + 1]; desorden = new int[cant + 1]; for (x = 1; x <= cant; x++) { Console.WriteLine("Ingrese el numero {0}", x); numero[x] = int.Parse(Console.ReadLine()); desorden[x] = numero[x]; } //mtodo burbuja para ordenar los numeros ingresados.

for (x = 1; x <= cant - 1; x++) { for (y = 1; y <= cant - x; y++) { if (numero[y] > numero[y + 1]) { auxiliar = numero[y]; numero[y] = numero[y + 1]; numero[y + 1] = auxiliar; } } } Console.WriteLine("Nmeros ordenados descendentemente son:

");

for (x = (cant); x >= 1; x--) { Console.WriteLine("{0}\t\t\t\t\t\t{1}", numero[x], desorden[x]); } Console.WriteLine("EL MENOR ES :"); for (x = (cant); x >= 1; x--) { Console.WriteLine("{0}",numero[x=1]); } Console.WriteLine("EL MAYOR ES :"); for (x = 1; x <= cant; x++) { Console.WriteLine("{0}", numero[x = cant]); } } } }

10.CUADRADO MGICO.
using System; using System.Collections.Generic; using System.Text;

namespace ConsoleApplication79 { class program {

static int Main(string[] args) {

int[] Mat; Mat = new int[3*3];

int p, m; p = 0; m = 3 / 2;

for (int i = 1; i <= 3*3; i++) { Mat[p * 3 + m] = i; if (i % 3 == 0) p++; else { if (p == 0) p = 3 - 1; else p--; if (m == 3 - 1) m = 0;

else m++; } } m = 1; Console.WriteLine("El cuadrado mgico de 3*3 es:"); Console.WriteLine(""); for (p = 0; p < 3 * 3; p++) { Console.Write(" {0,3}", Mat[p]); if (m >= 3) { Console.Write("\n"); m = 1; } else m++; } } } }

11.PROGRAMA PARA HALLAR EL PROMEDIO DE NOTAS MEDIAS DE UN DETERMINADO NUMERO DE ALUMNOS.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication87 { class Program { static void Main(string[] args)

{ int nAlumnos; do { Console.Write("Numero de alumnos: "); nAlumnos=int.Parse(Console.ReadLine()); } while(nAlumnos<1); float[] nota; nota = new float[nAlumnos]; int i = 0; float suma = 0F; Console.WriteLine("Introducir las notas medias del curso"); for (i = 0; i < nota.Length; i++) { Console.Write("Nota media de curso "); nota[i]=float.Parse(Console.ReadLine()); } for (i = 0; i < nota.Length;i++ ) suma=suma+ nota[i]; Console.WriteLine("\n\nNota media del curso:"+suma/nAlumnos); }

} }

12.HACER UN PROGRAMA PARA INGRESAR NOMBRES Y RESTRINGIR PARA VALORES POSITIVOS.PREGUNTAR SI SE QUIERE MOSTRAR.
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication92 { class Program { static void Main(string[] args) { int nFilas = 0, fila = 0; do { Console.Write("numero de filas de la matriz: nFilas = int.Parse(Console.ReadLine()); } while (nFilas < 1); string[] nombre;

");

nombre = new string[nFilas]; Console.WriteLine("Escriba los nombres q desea introducir"); Console.WriteLine("Puede finalizar pulsando las teclas [Ctrl] for (fila = 0; fila < nFilas; fila++) { Console.Write("Nombre["+fila+"]:"); nombre[fila] = Console.ReadLine(); if(nombre[fila]==null)break; } Console.WriteLine(); nFilas = fila; char respuesta; do { Console.Write("Desea visualizar el contenido de la matriz? (s/n):"); } respuesta=((Console.ReadLine()).ToLower())[0]; while(respuesta!='s'&&respuesta!='n'); if(respuesta=='s') { Console.WriteLine(); for(fila=0;fila<nFilas;fila++) Console.WriteLine(nombre[fila]); } } } }

[Z]");

13.HACER UN PROGRAMA PARA HALLAR EL MAXIMO Y MINIMO DE UN CONJUNTO DE VALORES.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication94 { class Program { static void Main(string[] args) { int nElementos; do { Console.WriteLine("Numero de valores q desea introducir"); nElementos=int.Parse(Console.ReadLine()); }

while(nElementos<1); float[] dato; dato = new float[nElementos]; int i=0; float max, min; for (i = 0; i < dato.Length; i++) { Console.Write("dato["+i+"]="); dato[i] = float.Parse(Console.ReadLine()); if (float.IsNaN(dato[i])) break; } nElementos = i; max=min=dato[0]; for(i=0;i<nElementos;i++) { if (dato[i] > max) max = dato[i]; if (dato[i] < min) min = dato[i]; } Console.WriteLine("valor maximo:{0} ",max); Console.WriteLine("valor mnimo:{0}",min); } } }

14.HACER UN PROGRAMA QUE CUENTE EL NUMERO DE VECES QUE APARECE CADA UNA DE LAS LETRAS DE UN TEXTO INTRODUCIDO POR TECLADO?.
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication95 { class Program { static void Main(string[] args) { int[]c; c = new int['z' - 'a' + 1]; int car; Console.WriteLine("Inruducir un texto"); Console.WriteLine("Para finalizar pulsar [Ctrl][z]\n");

while ((car = Console.Read()) != -1) { if (car >= 'a' && car <= 'z') c[car - 'a']++; } Console.WriteLine("\n"); for (car = 'a'; car <= 'z'; car++) Console.WriteLine("\n----------" + "-----------"); for (car = 'a'; car <= 'z'; car++) Console.Write(""+c[car-'a']); Console.WriteLine(); }

} }

15.HACER UN PROGRAMA EN C # DONDE DE DEBE INGRESAR 12 NMEROS ENTEROS DE DOS DGITOS NECESARIAMENTE EN UN ARRAY LLAMADO NUM1 Y DEBE RALIZAR LO SIGUIENTE: A).-EN UN ARRAY LLAMADO INVERTIDO ESCRIBIR LOS NUMEROS EN FORMA INVERTIDA Y MOSTRAR. B).-EN UN ARRAY PARIMPAR ESCRIBIR 2 SI EL NUMERO ES PAR Y 1 SI EL NUMERO ES IMPAR Y MOSTRAR. C).-EN UN ARRAY TRESDIG AGREGAR UN CERO ENTRE LOS DOS DIGITOS Y MOSTRAR. D).-EN UN ARRAY TOTAL GUARDAR LA MULTIPLICACION DEL ARRAY NUM1*2 Y ARRAY INVERTIDO/2 Y MOSTRAR.
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication109 { class Program {

static void Main(string[] args) { int[] NUM1; int[] INVERTIDO; int[] PARIMPAR; int[] TRESDIG; double[] TOTAL; int pdigito, sdigito, i; NUM1 = new int[12]; INVERTIDO = new int[12]; PARIMPAR = new int[12]; TRESDIG = new int[12]; TOTAL = new double[12]; //ingreso de datos

for (i = 0; i < 12; i++) { do { {0}", i); Console.WriteLine("Ingrese los datos en la posicin: NUM1[i] = int.Parse(Console.ReadLine()); } while (!((NUM1[i] >= 9) && (NUM1[i] <= 100))); }

//invertimos el numero for (i = 0; i < 12; i++) { pdigito = NUM1[i] / 10; sdigito = NUM1[i] % 10; INVERTIDO[i] = sdigito * 10 + pdigito; } //Si el numero es par escribios 2, si es impar escribimos 1 for (i = 0; i < 12; i++) { if ((NUM1[i] % 2) == 0) PARIMPAR[i] = 2; else PARIMPAR[i] = 1; } //agregamos un cero entre los digitos for (i = 0; i < 12; i++) {

pdigito = NUM1[i] / 10; sdigito = NUM1[i] % 10; TRESDIG[i] = pdigito * 100 + sdigito; } //lista NUM*2+INVERTIDO/2.0 for (i = 0; i < 12; i++) { TOTAL[i] = 2 * NUM1[i] + INVERTIDO[i] / 2.0; } //mostrar los arrays Console.WriteLine("Numero, Invertido Par/impar Tres digitos Total"); Console.WriteLine("****************************************** *******************************"); for (i = 0; i < 12; i++) { Console.Write("{0}\t\t {1}\t\t {2}\t\t {3}\t\t {4}\t\t", NUM1[i], INVERTIDO[i], PARIMPAR[i], TRESDIG[i], TOTAL[i]); Console.WriteLine(""); } } } }

16.HACER UN PROGRAMA
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication110 { class Program { static void Main(string[] args) { double[] PRECIO; double[] CANTIDAD; double[] MONTO; double[] DESCUENTO; double[] TRESDIG;

double[] INVERTIR; PRECIO = new double[4]; CANTIDAD = new double[4]; MONTO = new double[4]; DESCUENTO = new double[4]; TRESDIG = new double[4]; INVERTIR=new double[4]; int i; Console.WriteLine("PRECIO"); for (i = 0; i < 4; i++) { do { {0}", i); } Console.WriteLine("Ingrese precio en la posicin: PRECIO[i] = double.Parse(Console.ReadLine());

while (!((PRECIO[i] >= 50) && (PRECIO[i] <= 100))); } Console.WriteLine("CANTIDAD"); for (i = 0; i < 4; i++) { do { Console.WriteLine("Ingrese cantidad en la posicin: {0}", i); } } while (!((CANTIDAD[i] >= 0) && (CANTIDAD[i] <= 20))); CANTIDAD[i] = double.Parse(Console.ReadLine());

for (i = 0; i < 4; i++) { MONTO[i] = PRECIO[i]*CANTIDAD[i] ; } for (i = 0; i < 4; i++) { DESCUENTO[i] = (0.1) * MONTO[i]; } for (i = 0; i < 4; i++) { if((MONTO[i] >= 0) && (MONTO[i] <= 1000)) TRESDIG[i] = 1; if((MONTO[i] > 1000) && (MONTO[i] < 1500)) TRESDIG[i] = 2;

if((MONTO[i] >= 1500) && (MONTO[i] <= 2000)) TRESDIG[i] = 3; }

Console.WriteLine("precio cantidad monto tresdig "); Console.WriteLine("****************************************** *********************************"); for (i = 0; i < 4; i++) { Console.Write("{0}\t\t {1}\t\t {2}\t\t {3}\t\t {4}\t\t ", PRECIO[i], CANTIDAD[i], MONTO[i], DESCUENTO[i], TRESDIG[i] ); Console.WriteLine(""); descuento } }

} }

17.HACER UN PROGRAMA PARA DETERMINAR EL NUMERO DE PARES E IMPARES DE UNA LISTA.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication111 { class Program { static void Main(string[] args) { int impares = 0, pares = 0; int[] arr = new int[] { 1, 2, 3}; foreach(int i in arr) if(i%2==0) pares++; else impares++; Console.WriteLine("Hay {0} pares y {1} impares",pares,impares); } } }

18.PROGRAMA QUE UNE 2 LISTAS EN UNA NUEVA.

using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication130 { class Program { static void Main(string[] args) { int[] A; int m; A"); Console.WriteLine("cantidad de numeros a ingresar enla matriz m = int.Parse(Console.ReadLine()); A = new int[m]; for (int a = 0; a < m; a++) { Console.WriteLine("ingresa la posicion {0} :", a); A[a] = int.Parse(Console.ReadLine()); } int[] B; int n; Console.WriteLine("cantidad de num a ingresar en la matriz B"); n = int.Parse(Console.ReadLine()); B = new int[n]; for (int a = 0; a < n; a++) { Console.WriteLine("ingresa la posicion {0} :", a); B[a] = int.Parse(Console.ReadLine()); } int[] C; C = new int[m+n]; for (int a = 0; a < m; a++) { C[a] = A[a]; } for (int d = m; d < m+n; d++) { C[d] = B[d - m]; } Console.WriteLine("la matriz final C es:"); for (int x = 0; x < m + n; x++) { Console.WriteLine("{0}", C[x]); } Console.WriteLine(""); Console.ReadLine(); } } }

19.PROGRAMA QUE AGREGA NOMBRES A LOS YA EXITENTES Y MUESTRE.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication123 { class Program { static void Main() { string[] jugadores; jugadores = new string[100]; asignar(jugadores); for (int t = 0; t <= 5; t++) Console.WriteLine(jugadores[t]); } public static void asignar(params string[] fichas) { fichas[0] = "martina"; fichas[1] = "joan"; fichas[2] = "ana"; for (int t = 3; t <= 5; t++) { Console.WriteLine("entra jugador n {0}", t); string teclado = Console.ReadLine(); fichas[t] = teclado; } } } }

20.PROGRAMA CAMBIE LOS NUMEROS REPETIDOS POR CERO.?

using System;

using System.Collections.Generic; using System.Text; namespace ConsoleApplication136 { class Program { static void Main(string[] args) { int x, y, cant, auxiliar; Console.WriteLine("Cuantos numeros va ha ingresar"); cant = int.Parse(Console.ReadLine()); int[] numero; numero = new int[cant + 1]; for (x = 1; x <= cant; x++) { Console.WriteLine("Ingrese el numero {0}", x); numero[x] = int.Parse(Console.ReadLine()); } //mtodo burbuja para ordenar los numeros ingresados. for (x = 1; x <= cant - 1; x++) { for (y = 1; y <= cant - x; y++) { if (numero[y]==numero[y + 1]) { numero[y] = 0; numero[y + 1] = 0; } } } Console.WriteLine("Nmeros iguales q se cambian por cero son: "); for (x = 1; x <= (cant); x++) { Console.WriteLine("{0}", numero[x]); } } } }

21.ORDENAR UN DETERMINADO NUMERO DE NUMEROS ENFORMA DESCENEDENETE.

using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication139 { class Program { static void Main() { int[] a = { 54, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; string salida = "Valores de los items originales\n"; for ( int i = 0; i < a.Length; i++ ) salida += " " + a[ i ]; // ordenar elementos del arreglo OrdenarBurbuja( a ); salida += "\n\nValores de los items en orden descendente\n"; for ( int i = 0; i < a.Length; i++ ) salida += " " + a[ i ]; Console.WriteLine(salida); } // fin del <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">metodo</B> main // ordenar elementos de un arreglo con el <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">metodo</B> <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">burbuja</B> static public void OrdenarBurbuja( int[] b ) { for ( int pasadas = 1; pasadas < b.Length; pasadas++ ) // pasadas for ( int i = 0; i < b.Length - 1; i++ ) if ( b[ i ] > b[ i + 1 ] ) // comparar intercambio( b, i ); // intercambiar } // intercambio de dos elementos en un arreglo static public void intercambio( int[] c, int primero ) { int temp; // variable temporal para el intercambio temp = c[ primero ]; c[ primero ] = c[ primero + 1 ]; c[ primero + 1 ] = temp; } } }

23. SUMAR ELEMENTOS DE UN ARRAY.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication140

{ class Program { // metodo Main static void Main(string[] args) { int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int total = 0; for (int i = 0; i < a.Length; i++) total=total+a[i]; Console.WriteLine("Suma de todos los elementos del array: " + total); } // fin de Main } // fin de la clase SumarArreglo }

24.CALIFICACION MAS BAJA.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication140 { class Foreach { static void Main(string[] args) { int[,] calificaciones = { { 77, 68, 86, 73 }, { 98, 87, 89, 81 }, { 70, 90, 86, 81 } }; int baja = 100; foreach (int calificacion in calificaciones) { if (calificacion < baja) baja = calificacion; } Console.WriteLine("La calificacion mas baja es: " + baja); }

} }

24.ORDENAR UNA DETERMINADA LISTA DE NUMEROS YA DADOS.

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

namespace ConsoleApplication142 { class Program { public static void Main(string[] args) { int[] a = new int[] { 1, 4, 6, 8, 9, 0 }; Console.WriteLine("Antes de Ordenar:"); for (int i = 0; i < a.Length; i++) { System.Console.WriteLine("Valor {0}: {1}", i + 1, a[i]); } ordenar(a); Console.WriteLine("Despes de Ordenar:"); for (int i = 0; i < a.Length; i++) { System.Console.WriteLine("Valor {0}: {1}", i + 1, a[i]); } } static int[] ordenar(int[] a) { for (int i = 0; i < a.Length; i++) { for (int j = 0; j < a.Length - 1; j++) { if (a[j] > a[j + 1]) { int aux = a[j]; a[j] = a[j + 1]; a[j + 1] = aux; } } } return a; } } }

25.INGRESANDOA UNA LISTA IR DETERMINANDO SI ES PAR O IMPAR.

using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication146 { class Program {

static void Main(string[] args) { int[] NUM1; int x, cant; Console.WriteLine("INGRESE CANT de numeros "); cant = int.Parse(Console.ReadLine()); NUM1 = new int[cant+1]; for (x = 1; x <= cant; x++) { Console.WriteLine("ingrese el numero{0}", x); NUM1[x] = int.Parse(Console.ReadLine()); if (NUM1[x] % 2 == 0) Console.WriteLine("par"); else Console.WriteLine("impar"); } } } }

26.INGRESAR UN ARRAY Y DECIR SU UBICACION.

using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication148 { class Program { static void Main(string[] args) { { //declaramos el array int[] numero; //declaramos las variables int x,a, cant ; //cantidad de numeros que se ordenarn Console.WriteLine("Cual es la longitud del array"); cant = int.Parse(Console.ReadLine()); //definimos el tamao del array numero = new int[cant + 1]; //Ingresamos los numeros de acuerdo a la cantidad definida

for (x = 1; x <= cant; x++) { Console.WriteLine("Ingrese el dato {0}", x); numero[x] = int.Parse(Console.ReadLine()); } //imprime los numeros ordenados ascendentemente for (x = 1; x <= (cant); x++) { Console.WriteLine("que numero desea buscar "); a = int.Parse(Console.ReadLine()); for (x = 1; x <= (cant); x++) { if (a == numero[x]) { Console.WriteLine("si se encuentra en la posicion {0}", x); } } }

} } } }

25.INGRESAR UN ARRAY LA SUMA DE LOS PARES E IMPARES.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication153 { class Program { static void Main(string[] args) { int num; Console.WriteLine("Cuanto numeros desea ingresar: num = int.Parse(Console.ReadLine()); int[] numeros; numeros = new int[num]; int i; int sumapar = 0; int sumaimpar = 0;

");

for (i = 0; i < num; i++) { Console.WriteLine("Ingrese numeros {0}", i); numeros[i] = int.Parse(Console.ReadLine()); } Console.WriteLine(); Console.WriteLine("Los numeros ingresados son:"); for (i = 0; i < num; i++) { Console.WriteLine("Los numeros ingresados en la posicion {0} es {1}", i, numeros[i]); } for (i = 0; i < num; i++) { int suma=numeros[i]; { if (numeros[i] % 2 ==0)

sumapar = sumapar + numeros[i]; else sumaimpar = sumaimpar + numeros[i]; ; } } Console.WriteLine("la suma de los pares es: {0}", sumapar ); Console.WriteLine("la suma de los imparespares es: {0}", sumaimpar); } } }

26.INGRESAR UN ARRAY E INTERCAMBIAR LA PARTE DEL INICIO AL FINAL Y EL FINAL AL INICIO.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication156 { class Program { static void Main(string[] args)

{ int m; Console.WriteLine("cuantos numeros tendra la lista "); m = int.Parse(Console.ReadLine()); int[] M = new int[m]; for (int x = 0; x < m; x++) { Console.Write("M[{0}]= ", x); M[x] = int.Parse(Console.ReadLine()); } Console.WriteLine(""); int[] L = new int[m]; for (int x = 0; x < m / 2; x++) { if ((m % 2) == 0) L[x] = M[m / 2 + x]; } for (int x = m / 2; x < m; x++) { if ((m % 2) == 0) L[x] = M[x - m / 2]; } for (int x = 0; x < (m + 1) / 2; x++) { if ((m % 2) != 0) L[x] = M[(m + 1) / 2 - 1 + x]; } for (int x = (m + 1) / 2; x < m; x++) { if ((m % 2) != 0) L[x] = M[x - (m + 1) / 2]; }

} } }

Console.WriteLine("La lista alterada es:"); for (int x = 0; x < m; x++) { Console.WriteLine("{0}", L[x]); }

27.INTERCAMBIAR EL ORDEN DE DOS LISTAS.


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

namespace ConsoleApplication157 { class Program { static void Main(string[] args) { int[] lista1, lista2, lista3, lista4, auxiliar1, auxiliar2; int a; Console.WriteLine("cuantos_datos_desea_ingresar?"); a = int.Parse(Console.ReadLine()); lista1 = new int[a]; lista2 = new int[a]; lista3 = new int[a]; lista4 = new int[a]; auxiliar1 = new int[a]; auxiliar2 = new int[a];

Console.WriteLine("Ingrese_los_datos_de_la_lista_1"); for (int x = 0; x < a; x++) {

Console.WriteLine("dato_{0}_de_la_lista_1", x); lista1[x] = int.Parse(Console.ReadLine());

} Console.WriteLine("Ingrese_los_datos_de_la_lista_2"); for (int x = 0; x < a; x++) { Console.WriteLine("dato_{0}_de_la_lista_2", x); lista2[x] = int.Parse(Console.ReadLine());

} for (int x = 0; x < a; x++) { lista3[x] = lista1[x]; } for (int x = 0; x < a; x++) { lista4[x] = lista2[x]; } for (int x = 0; x < a; x++) { auxiliar1[a - 1 - x] = lista1[x];

} for (int x = 0; x < a; x++) { auxiliar2[a - 1 - x] = lista2[x]; }

Console.WriteLine("las_listas_ingresadas_son"); for (int x = 0; x < a; x++) { Console.WriteLine("{0}\t {1}\t", lista3[x], lista4[x]);

} Console.WriteLine("el_resultado_es:"); for (int x = 0; x < a; x++) { Console.WriteLine("{0}\t {1}\t", auxiliar2[x], auxiliar1[x]);

} Console.ReadLine(); }

} }

28.DADAS DOS LISTA IR INTERCAMBIANDO SUS DATOS.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication158 { class Program { static void Main(string[] args) { int a; int[] num1; int[] num2; int[] num3;

Console.Write("INGRESE EL TAMAO DE LAS LISTAS: "); a = int.Parse(Console.ReadLine()); num1 = new int[a + 1]; num2 = new int[a + 1]; num3 = new int[2 * a + 2]; Console.WriteLine("primera LISTA"); Console.WriteLine("-------------"); for (int b = 1; b <= a; b++) { num2[b] = int.Parse(Console.ReadLine()); } Console.WriteLine("segunda LISTA"); Console.WriteLine("-------------"); for (int b = 1; b <= a; b++) { num1[b] = int.Parse(Console.ReadLine()); } for (int b = 1; b <= a; b++) { num3[2*b] = num1[b]; num3[2 * b - 1] = num2[b]; } Console.WriteLine("LISTA final es:"); Console.WriteLine("----------------"); for (int b = 1; b <= (2 * a); b++) { Console.WriteLine("{0}", num3[b]); } } } }

Você também pode gostar