first commit
This commit is contained in:
76
listas4/src/exercicios4-5.cs
Normal file
76
listas4/src/exercicios4-5.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace exercicios
|
||||
{
|
||||
public class exercicio4
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
int[,] valores = new int[5,5];
|
||||
int somaTot = 0, somaLin = 0;
|
||||
|
||||
Console.WriteLine("Insert a value, press enter. End goal is to fill a 5x5 matrix.");
|
||||
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
valores[k,l] = int.Parse(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
foreach(int i in valores)
|
||||
{
|
||||
somaTot += i;
|
||||
}
|
||||
Console.WriteLine("Total sum:{0}",somaTot);
|
||||
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
somaLin = 0;
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
somaLin += valores[k,l];
|
||||
}
|
||||
Console.WriteLine("Line: {0}, Sum: {1}",k,somaLin);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class exercicio5
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
int[,] valores = new int[4,5];
|
||||
int ParMed, ImparMed, QtdPar, QtdImpar;
|
||||
ParMed = ImparMed = QtdImpar = QtdPar = 0;
|
||||
|
||||
Console.WriteLine("Insert a value, press enter. End goal is to fill a 4x5 matrix.");
|
||||
|
||||
for(int k = 0; k < valores.GetLength(0); k++)
|
||||
{
|
||||
for(int l = 0; l < valores.GetLength(1); l++)
|
||||
{
|
||||
valores[k,l] = int.Parse(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
foreach(int i in valores)
|
||||
{
|
||||
if(i % 2 == 0)
|
||||
{
|
||||
QtdPar++;
|
||||
ParMed += i;
|
||||
}
|
||||
else
|
||||
{
|
||||
QtdImpar++;
|
||||
ImparMed += i;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Odd: {0}, Even: {1}, Sum Odd: {2}, Sum Even: {3}, Avg. Odd: {4:N2}, Avg. Even: {5:N2}",
|
||||
QtdImpar,QtdPar,ParMed,ImparMed,(double)ImparMed/QtdImpar,(double)ParMed/QtdPar);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user