79 lines
1.8 KiB
C#
79 lines
1.8 KiB
C#
namespace _2023._09._06;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
class Program
|
|
{
|
|
static void Feladat1()
|
|
{
|
|
const int m = 4;
|
|
const int n = 4;
|
|
|
|
int[,] matrix = new int[m, n];
|
|
Random r = new Random();
|
|
for (int i = 0; i < m; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
matrix[i, j] = r.Next(1, 100);
|
|
}
|
|
}
|
|
System.Console.WriteLine("Az eredeti mátrix: ");
|
|
for (int i = 0; i < m; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
System.Console.SetCursorPosition(i * 10, 2 + (j * 2));
|
|
System.Console.WriteLine(matrix[i, j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void Feladat2()
|
|
{
|
|
int[] tomb = new int[10];
|
|
Random r = new Random();
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
int szam = r.Next(1, 101);
|
|
tomb[i] = szam;
|
|
}
|
|
|
|
Array.Sort(tomb);
|
|
|
|
foreach (int elem in tomb)
|
|
{
|
|
System.Console.WriteLine(elem);
|
|
}
|
|
}
|
|
|
|
static void Feladat3()
|
|
{
|
|
int[] tomb = {};
|
|
|
|
System.Console.WriteLine("Írj be számokat! Kilépni a nulla szám leütésével tudsz!");
|
|
int szam = Convert.ToInt32(System.Console.ReadLine());
|
|
do
|
|
{
|
|
tomb.Append(szam).ToArray();
|
|
szam = Convert.ToInt32(System.Console.ReadLine());
|
|
|
|
}
|
|
|
|
while (szam != 0);
|
|
|
|
foreach (int elem in tomb)
|
|
{
|
|
System.Console.WriteLine(elem);
|
|
}
|
|
|
|
System.Console.WriteLine($"A számok összege: {tomb.Sum()}");
|
|
System.Console.WriteLine($"A számok átlaga: {tomb.Average()}");
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Feladat3();
|
|
}
|
|
} |