Você está na página 1de 7

EX:

int[,] nros = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 9, 10 } };

int f = 0;
for (int c = 0; c < 5; c++)
{
for (int l = 0; l < 2; l++)
{
f++;
Console.Write(nros[c, l] + " ");

}
Console.WriteLine();
}

//1. Ler um vetor com 10 inteiros e mostrar os números na ordem direta e inversa a que foram
lidos.
int[] x = new int[10];
int i;
Console.WriteLine("Digite 10 valores inteiros");
for (i = 0; i < 10; i++)
x[i] = int.Parse(Console.ReadLine());
Console.WriteLine("Ordem inversa");
for (i = 9; i >= 0; i--)
Console.WriteLine(x[i]);
Console.ReadKey();

//2. Ler um vetor com 10 inteiros e mostrar o maior e o menor elemento do vetor
int[] x = { 2,5,8,6,4,5,1,10,0,9 };
Array.Sort(x);
Console.WriteLine(x[1]);
Console.WriteLine(x.GetLength(0));

//3. Escreva um algoritmo que leia um vetor de 100 elementos inteiros. Encontre e mostre o
maior elemento e a sua posição

int maior = 0;
int posi=0;

int[] matriz = new int[100];


Random rnum = new Random();
Console.WriteLine("POS NUM");
for (int i = 0; i < 100;i++)
{
int ramdomnumber = rnum.Next(0, 100);
matriz[i] = ramdomnumber;
Console.Write(i + " ");
Console.WriteLine(matriz[i] );
if(maior < matriz[i])
{
maior = matriz[i];
posi = i;
}
}

Console.WriteLine("O maior numero é o {0} e esta na posição {1}",maior,posi);

//4. Faça um algoritmo que leia dois vetores de 10 elementos numéricos cada um e intercale os elementos deste
em um outro vetor de 20 elementos.

int[] matriz = new int[10];


int[] matriz2 = new int[10];
int[] matrizs = new int[20];

Random rnum = new Random();


Console.WriteLine("POS NUM");
for (int i = 0; i < 10;i++)
{
int ramdomnumber = rnum.Next(0, 100);
matriz[i] = ramdomnumber;
Console.Write(i + " ");
Console.WriteLine(matriz[i] );

Console.WriteLine("POS NUM");
for (int i = 0; i < 10; i++)
{
int ramdomnumber = rnum.Next(0, 100);
matriz2[i] = ramdomnumber;
Console.Write(i + " ");
Console.WriteLine(matriz2[i]);

}
int j = 0;
Console.WriteLine("POS NUM");
for (int i = 0; i < 20; i++)
{
j = i / 2;
if(i % 2 == 0)
{
matrizs[i] = matriz[j];
}
else
{
matrizs[i] = matriz2[j];
}

Console.Write(i + " ");


Console.WriteLine(matrizs[i]);

//5. Escreva um algoritmo que leia um vetor de 10 posições de números inteiros e imprimir,
logo após, gerar 2 vetores a partir dele, um contendo os elementos de posições ímpares do
vetor e o outro os elementos de posições pares. Imprimi-los no final.
int[] matriz = new int[10];
int[] matriz2 = new int[5];
int[] matriz3 = new int[5];

Random rnum = new Random();


Console.WriteLine("POS NUM");
for (int i = 0; i < 10;i++)
{
int ramdomnumber = rnum.Next(0, 100);
matriz[i] = ramdomnumber;
Console.Write(i + " ");
Console.WriteLine(matriz[i] );

Console.WriteLine("POS NUM");
Console.WriteLine();
for (int i = 0; i < 5; i++)
{

matriz2[i] = matriz[i*2] ;
Console.Write(i + " ");
Console.WriteLine(matriz2[i]);
}
Console.WriteLine("POS NUM");
Console.WriteLine();

for (int i = 0; i < 5; i++)


{

matriz3[i] = matriz[(i * 2)+1];


Console.Write(i + " ");
Console.WriteLine(matriz3[i]);
}

//6. Ler uma matriz 5 x 5 e mostrar o maior e menor elemento da matriz. E depois a soma dos
elementos.
int[,] m = new int[5, 5];
int maiorl = 0, maiortotal = 0, menorl = 999,menortotal =999;

Console.WriteLine("Leitura:");
for (int l = 0; l <= m.GetLength(0) - 1; l++)
{
Console.WriteLine((l + 1) + "ª linha:");

for (int c = 0; c <= m.GetLength(1) - 1; c++)


{
Console.WriteLine("Digite o {0}º numero da {1}ª linha",c+1,l+1);
m[l, c] = int.Parse(Console.ReadLine());
if (menorl > m[l, c])
{
menorl = m[l, c];
}
else
{
menorl = menorl;
}
if (maiorl < m[l, c])
{
maiorl = m[l, c];
}
else
{
maiorl = maiorl;
}

Console.WriteLine("O maior numero é {0} e o menor numero é {1} e a soma entre ambos é
{2}",maiortotal,menortotal,(maiortotal +menortotal));

//7. Ler duas matrizes 3 x 3 e calcular a soma das matrizes


int[,] a1 = new int[3, 3]
{
{ 1,2,3}, {3,4,5} , {6,7,8 }
};

int[,] a2 = new int[3, 3]


{
{ 1,2,3}, {3,4,5} , {6,7,8 }
};

int[,] asoma = new int[3, 3];

for (int col = 0; col < 3; col++)


{
for (int lin = 0; lin < 3; lin++)
{

asoma[lin, col] = a1[lin, col] + a2[lin, col];


}
}

for (int c = 0; c < 3; c++)


{
for (int l = 0; l <3; l++)
{
Console.Write(asoma[c, l] + " ");

}
Console.WriteLine();
}

//8. Ler duas matrizes 2 x 2 e calcular o produto entre as matrizes.(multiplicação)

int[,] a1 = new int[2, 2] {


{ 1,2}, {3,4} };

int[,] a2 = new int[2, 2] {


{ -1, 3}, {4,2} };

int[,] amult = new int[2, 2] {


{ (a1[0,0] * a2[0,0]) + (a1[0,1] * a2[1,0]) , (a1[0,0] * a2[0,1]) +(a1[0,1] * a2[1,1]) } ,
{ (a1[1,0] * a2[0,0]) +(a1[1,1] * a2[1,0]) , (a1[0,0] * a2[1,1]) +(a1[1,1] * a2[1,1]) }

};

int i, j;
Console.WriteLine("Matriz");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
Console.Write("{0,2} ", amult[i, j]);
Console.WriteLine();
}
Console.WriteLine(a1[0, 0]);
Console.WriteLine(a2[0, 0]);
Console.WriteLine(a1[0, 1]);
Console.WriteLine(a2[1, 0]);

Console.WriteLine(amult[0, 0]);

//9. Ler uma matriz M[5,5] e escrever :

//o maior elemento de cada linha da matriz;

//a média dos elementos de cada coluna

int maior,soma = 0;
int[,] matriz = new int[5, 5];

Random rnum = new Random();


for (int col = 0; col < 5; col++)
{
for (int lin = 0; lin < 5; lin++)
{

int ramdomnumber = rnum.Next(0, 100);

matriz[lin, col] = ramdomnumber;


}
}

for (int c = 0; c < 5; c++)


{
for (int l = 0; l < 5; l++)
{
Console.Write(matriz[c, l] + " ");

}
Console.WriteLine();
}

for (int lin = 0; lin < 5; lin++)


{
maior = 0;
for (int col = 0;col < 5;col++)
{

if (maior < matriz[lin,col])


{
maior = matriz[lin, col];
}

}
Console.WriteLine("O maior numero da linha {0} é: {1}",lin , maior);

Console.WriteLine();
for (int c = 0; c <= matriz.GetLength(1) - 1; c++)
{
soma = 0;

for (int l = 0; l <= matriz.GetLength(0) - 1; l++)


{
soma = soma + matriz[l, c];
}

soma = soma / matriz.GetLength(0);

Console.WriteLine("Média da " + (c + 1) + "ª coluna é: " + soma);


}
Console.ReadLine();

/*10. Leia um número inteiro X e uma matriz M[10,10] de inteiros

-Conte quantos valores iguais a X existem na matriz.

-Conte quantos valores maiores do que X existem na matriz */

int[,] matriz = new int[10, 10];

Random rnum = new Random();


for (int col = 0; col < 10; col++)
{
for (int lin = 0; lin < 10; lin++)
{

int ramdomnumber = rnum.Next(0, 10);

matriz[lin, col] = ramdomnumber;


}
}

for (int c = 0; c < 10; c++)


{
for (int l = 0; l < 10; l++)
{
Console.Write(matriz[c, l] + " ");

}
Console.WriteLine();
}

Console.WriteLine("Introduza um numero : ");


int numero = int.Parse(Console.ReadLine());
int conta = 0;
int maior = 0;
for (int col = 0; col < 10; col++)
{
for (int lin = 0; lin < 10; lin++)
{
if (numero == matriz[lin, col])
{
conta++;
}
if (numero < matriz[lin, col])
{
maior++;
}
}
}
Console.WriteLine(numero + " ocorre " + conta + " vezes ");
Console.WriteLine("Há {0} numeros maiores que {1}",maior,numero);

/* 10 Ler as notas de 80 alunos, armazená-las num array e calcular:

-a média das notas e o número de notas acima da média

-a maior nota e a quantidade de alunos que tiveram a maior nota

-a menor nota e os índices (posição do array) dos alunos que tiveram a maior nota

-o número de alunos com nota negativa*/

Você também pode gostar