I have a question in a program Basically the program says the following: Finding the largest value of each row, of each column and the largest of the entire matrix, is a 4x7 matrix. Actually the program is a menu with more options but I already have all, I just do not know how to find the largest value of the row and column, the highest value of the whole matrix also I get the only problem is with the columns and rows.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ULTIMOEXAMEN
{
class Examen
{
public float[,] matriz;
public void iniciar()
{
matriz = new float[4, 7];
for (int f = 0; f < 4; f++)
{
for (int c = 0; c < 7; c++)
{
Console.Write("Ingrese posicion [" + (f + 1) + "," + (c + 1) + "]: ");
string linea;
linea = Console.ReadLine();
matriz[f, c] = float.Parse(linea);
}
}
}
public void menu()
{
Console.WriteLine("ELEGIR UNA OPCION: ");
Console.WriteLine("1- SUMAS");
Console.WriteLine("2- MAYOR");
Console.WriteLine("3- ESCALAR");
Console.WriteLine("4- SALIR");
switch (Console.Read())
{
case '1':
//SUMA DE FILAS
for (int f = 0; f < 4; f++)
{
float suma = 0;
for (int c = 0; c < 7; c++)
{
suma += matriz[f, c];
}
Console.WriteLine("FILA " + f + " = " + suma);
}
//SUMA DE COLUMNAS
for (int c = 0; c < 7; c++)
{
float suma = 0;
for (int f = 0; f < 4; f++)
{
suma += matriz[f, c];
}
Console.WriteLine("COLUMNA " + c + " = " + suma);
}
break;
case '2':
//EL MAYOR DE TODA LA MATRIZ
float mayortodo = 0;
float mayor = matriz[0, 0];
for (int f = 0; f < 4; f++)
{
for (int c = 0; c < 7; c++)
{
if (matriz[f, c] > mayortodo)
{
mayor = matriz[f, c];
mayortodo = mayor;
}
}
}
Console.WriteLine("EL ELEMENTO MAYOR DE LA MATRIZ ES:" + mayortodo);
//EL MAYOR DE CADA FILA
float mayorfila = 0;
float mayor2 = matriz[0,0];
for( int f=0; f<4; f++)
{
for (int c=0; c<7; c++)
{
if(matriz[f,c]>mayorfila)
{
mayor2 = matriz[f, c];
mayorfila = mayor2;
}
}
}
Console.WriteLine("EL ELEMENTO MAYOR DE LA FILA ES: " + mayorfila);
break;
case '3':
break;
case '4':
System.Environment.Exit(4);
Console.ReadKey();
break;
}
}
static void Main(string[] args)
{
Examen ex = new Examen();
ex.iniciar();
ex.menu();
Console.ReadKey();
}
}
}