Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TP1Punto3
- {
- class Program
- {
- static void cargarMatriz(int[,] mat)
- {
- Console.Clear();
- for (int j = 0; j < mat.GetLength(1); j++)
- {
- Console.Clear();
- Console.WriteLine("Fila {0}" , j+1 );
- for (int i = 0; i < mat.GetLength(0); i++)
- {
- mat[i, j] = int.Parse(Console.ReadLine());
- }
- }
- }
- static void mostrarMatriz(int[,] mat)
- {
- Console.Clear();
- Console.WriteLine("Matriz: ");
- Console.WriteLine("");
- for (int j = 0; j < mat.GetLength(1); j++)
- {
- for (int i = 0; i < mat.GetLength(0); i++)
- {
- Console.Write("\t" + mat[i, j]);
- }
- Console.WriteLine("");
- }
- }
- static void sumaDiagonal(int[,] mat)
- {
- int suma = 0;
- for (int i = 0; i < mat.GetLength(0); i++)
- {
- bool aux = true;
- int j = 0;
- while (aux)
- {
- if (i==j)
- {
- suma = suma + mat[i, j];
- aux = false;
- }
- else
- {
- j = j + 1;
- }
- }
- }
- Console.WriteLine("\nLa suma de la diagonal principal es: " + suma);
- Console.WriteLine("\n\nPresione una tecla para continuar..");
- Console.ReadKey();
- }
- static void mensaje(ref int resp)
- {
- Console.Clear();
- Console.WriteLine("Elija una opcion");
- Console.WriteLine("\n1-Nueva matriz.");
- Console.WriteLine("\n2-Salir.");
- resp = int.Parse(Console.ReadLine());
- }
- static void Main(string[] args)
- {
- int resp = 0;
- do
- {
- Console.Clear();
- Console.WriteLine("Ingrese la dimension de la matriz..");
- int dim = int.Parse(Console.ReadLine());
- int[,] matriz = new int[dim, dim];
- cargarMatriz(matriz);
- mostrarMatriz(matriz);
- sumaDiagonal(matriz);
- mensaje(ref resp);
- } while (resp!=2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement