vojta249

Maturita_16 - max cislo funkce

May 4th, 2022 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Program
  4. {
  5.     class Program
  6.     {
  7.         public static int max(int[] pole)
  8.         {
  9.             //max je nejnizsi mozna hodnota z randomu
  10.             int max = -100;
  11.             for (int j = 0; j < pole.Length; j++)
  12.             {
  13.                 if (pole[j] > max)
  14.                     max = pole[j];
  15.             }
  16.             return max;
  17.         }
  18.         public static void Main(string[] args)
  19.         {
  20.             Random random = new Random();
  21.             int[] pole = new int[5];
  22.             for (int i = 0; i < 5; i++)
  23.             {
  24.                 pole[i] = random.Next(-100, 100);
  25.             }
  26.             //vypsani pole pro kontrolu
  27.             for (int i = 0; i < 5; i++)
  28.             {
  29.                 Console.Write(pole[i] + " ");
  30.             }
  31.             Console.WriteLine("\nNejvyšší číslo je {0}. ", max(pole));
  32.             Console.ReadKey();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment