Einführung in C#
Minimum und Maximum - Programmierbeispiel Min - Max
Hier ein Programm, welches bei Eingabe von n-verschiedenen Zahlen das Minimum und das Maximum berechnet:
namespace min_max { class Program { static void Main(string[] args) { int i=1; float zahlen,zahl,min=0,max=0; Console.Write("Wieviele Zahlen?"); zahlen = Convert.ToSingle(Console.ReadLine()); do { Console.WriteLine("{0} Zahl? ", i); zahl = Convert.ToInt32(Console.ReadLine()); if (i == 1) { min = zahl; max = zahl; } else { if (zahl < min) min = zahl; else if (zahl > max) max = zahl; } i++; } while (i <= zahlen); Console.WriteLine("Minimum = {0}\tMaximum = {1}", min,max); Console.ReadLine(); } } }