update
This commit is contained in:
66
MinMax/Adat.cs
Normal file
66
MinMax/Adat.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MinMax {
|
||||
public class Adat {
|
||||
private int[] numbers = new int[Int32.MaxValue/8];
|
||||
|
||||
public Adat() {
|
||||
Console.WriteLine("Akarsz e megadni adatot? (Igen/Nem)");
|
||||
string user = Console.ReadLine();
|
||||
|
||||
if (user.Equals("Igen") || user.Equals("igen")) {
|
||||
Console.WriteLine("Adja meg hany elemet akar bevinni");
|
||||
int number = Convert.ToInt32(Console.ReadLine());
|
||||
|
||||
numbers = new int[number];
|
||||
setNumber(false);
|
||||
} else {
|
||||
setNumber(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNumber(bool rand, int[] numbers = null) {
|
||||
if (!rand) {
|
||||
if(numbers != null) {
|
||||
this.numbers = numbers;
|
||||
} else {
|
||||
Console.WriteLine("Adja meg az elemeket!");
|
||||
for (int i = 0; i<this.numbers.Length; i++) {
|
||||
this.numbers[i] = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Random random = new Random();
|
||||
//random elemek hozzaadasa a tombhoz
|
||||
for (int i = 0; i < this.numbers.Length; i++) {
|
||||
this.numbers[i] = random.Next(Int32.MinValue / 2, Int32.MaxValue / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int min() {
|
||||
int min = numbers[0];
|
||||
for (int i = 0; i < numbers.Length; i++) {
|
||||
if (numbers[i] < min) {
|
||||
min = numbers[i];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public int max() {
|
||||
int max = numbers[0];
|
||||
for (int i = 0; i < numbers.Length; i++) {
|
||||
if (numbers[i] > max) {
|
||||
max = numbers[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Adat.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -5,41 +5,13 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MinMax {
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
Random random = new Random();
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
|
||||
int[] arr = new int[Int32.MaxValue/8];
|
||||
Adat adat = new Adat();
|
||||
|
||||
//random elemek hozzaadasa a tombhoz
|
||||
for (int i = 0; i < arr.Length; i++) {
|
||||
arr[i] = random.Next(Int32.MinValue,Int32.MaxValue);
|
||||
}
|
||||
|
||||
|
||||
//tomb elemeinek kiiratasa
|
||||
/*for (int i = 0; i < arr.Length; i++) {
|
||||
Console.WriteLine(arr[i]);
|
||||
}*/
|
||||
|
||||
int min = Int32.MaxValue;
|
||||
int min_i = -1;
|
||||
int max = Int32.MinValue;
|
||||
int max_i = -1;
|
||||
|
||||
for (int i = 0; i < arr.Length; i++) {
|
||||
if(min > arr[i]) {
|
||||
min = arr[i];
|
||||
min_i = i;
|
||||
}
|
||||
if (max < arr[i]) {
|
||||
max = arr[i];
|
||||
max_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Min ertek: {0}, helye: {1}",min,min_i);
|
||||
Console.WriteLine("Max ertek: {0}, helye: {1}", max, max_i);
|
||||
Console.WriteLine("Min: " + adat.min());
|
||||
Console.WriteLine("Max: " + adat.max());
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
a716bfef2e809d656a083b5be6f3dfe2908c1bec
|
||||
0eee36f483feb2dc702c6746942cc098363df435
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user