1. Dado N números enteros ingresados por teclado, determine el promedio de estos
01 static void Main(string[] args) 02 { 03 Console.Write("Cantidad de números a ingresar: "); 04 int cantidad = Convert.ToInt32(Console.ReadLine()); 05 int suma = 0; 06 Console.WriteLine(); 07 for (int i = 1; i <= cantidad; i++) 08 { 09 Console.Write(">Número {0}: ", i); 10 suma += Convert.ToInt32(Console.ReadLine()); 11 Console.WriteLine(); 12 } 13 14 int promedio = suma / cantidad; 15 16 Console.WriteLine("> El promedio es: {0} \n", promedio); 17 18 Console.WriteLine("+ Presione cualquier tecla pata terminar"); 19 Console.ReadKey(); 20 }
2. Dado N notas de alumnos de computación, se pide calcular
a) Cantidad de alumnos aprobados. Nota mínima 51 puntos
b) Cantidad de reprobados
c) Promedio de notas totales, aprobados y reprobados
01 static void Main(string[] args) 02 { 03 Console.Write("Cantidad de notas a ingresar: "); 04 int cantidad = Convert.ToInt32(Console.ReadLine()); 05 Console.WriteLine(); 06 07 int tAprobados = 0; 08 int tReprobados = 0; 09 double tNotaAprobados=0, tNotaReprobados=0, tNotaCurso=0; 10 11 for (int i = 1; i <= cantidad; i++) 12 { 13 Console.Write("> Nota {0}: ", i); 14 double nota = Convert.ToDouble(Console.ReadLine()); 15 Console.WriteLine(); 16 tNotaCurso += nota;//se acumula el total de las notas 17 if (nota >= 51)//alumnos aprobados 18 { 19 tAprobados++; 20 tNotaAprobados += nota; 21 } 22 else 23 { 24 tReprobados++; 25 tNotaReprobados += nota; 26 } 27 } 28 29 Console.WriteLine("> Alumnos aprobados {0} con un promedio de {1} puntos\n", tAprobados, Math.Round((tNotaAprobados/tAprobados),2)); 30 Console.WriteLine("> Alumnos reprobados {0} con un promedio de {1} puntos\n", tReprobados, Math.Round((tNotaReprobados / tReprobados),2)); 31 Console.WriteLine("> El promedio total del curso es de {0} puntos \n", Math.Round((tNotaCurso/cantidad),2)); 32 33 Console.WriteLine("+ Presione cualquier tecla pata terminar"); 34 Console.ReadKey(); 35 }
3. Dado un array de N números enteros positivos, desarrolle un programa que permita sumar por separados los números pares de los impares. Mostrar el resultado.
01 static void Main(string[] args) 02 { 03 04 int[] num = { 1, 34, 89, 15, 3, 17, 10, 32, 78, 98, 2, 4, 88 }; 05 06 int tPar = 0; 07 int tImpar = 0; 08 09 //suma de numeros 10 for (int i = 0; i < num.Length; i++ ) 11 { 12 if ((num[i] % 2) == 0)//es par 13 { 14 tPar += num[i]; 15 } 16 else 17 { 18 tImpar += num[i]; 19 } 20 } 21 Console.WriteLine("> Total suma números pares: {0} \n",tPar); 22 Console.WriteLine("> Total suma números impares: {0}", tImpar ); 23 24 Console.ReadKey(); 25 }
4. Desarrolle un programa para sumar dos matrices 3×3 usando métodos, un método para sumar y otro método para imprimir.
01 class Program 02 { 03 static void Main(string[] args) 04 { 05 06 int[,] a = { { 0, 2, 3 }, { 1, 2, 0 }, { 0, 2, 7 } }; 07 int[,] b = { { 1, 2, 1 }, { 4, 5, 6 }, { 0, 6, 1 } }; 08 09 10 Console.WriteLine("Matriz A"); 11 imprimir(a); 12 Console.WriteLine("\nMatriz B"); 13 imprimir(b); 14 Console.WriteLine("\nMatriz Resultantes"); 15 int[,] c = sumar(a, b); 16 imprimir(c); 17 18 Console.ReadKey(); 19 } 20 21 22 static int[,] sumar( int[,] a, int[,] b) 23 { 24 int[,] c = new int[3, 3]; 25 26 for (int fila = 0; fila < 3; fila++) 27 { 28 for (int col = 0; col < 3; col++) 29 { 30 c[fila, col] = a[fila, col] + b[fila, col]; 31 } 32 } 33 return c; 34 } 35 36 37 static void imprimir( int[,] matriz) 38 { 39 for (int f = 0; f < 3; f++) 40 { 41 for (int c = 0; c < 3; c++) 42 { 43 Console.Write(" {0} |",matriz[f,c]); 44 } 45 Console.WriteLine(""); 46 } 47 } 48 49 50 }
enjoy!!! 🙂
En este post se da respuesta a una pregunta realizada por facebook. El problema dice así: Se quiere personalizar un JTab[...]
En este tutorial crearemos una sencilla aplicación para android que nos permitirá subir una imagen a un servidor web. La[...]
El problema dice asi: Se desea contar los segundos que se presiona un JButton en un formulario. Solución: Para resolver[...]
¿Qué es javaFX? JavaFX es una familia de productos y tecnologías de Sun Microsystems, adquirida por Oracle Corporation,[...]
«Mouse Responde…» simula ser un alma en pena que responde cualquier pregunta que le hagan, al estilo del juego de[...]
Google tiene entre su formulario de autenticación de usuario para sus diferentes servicios (gmail, blogger, youtube, g+)[...]