Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. namespace HelloWorld
  3. {
  4.     class Hello
  5.     {
  6.         static void Main()
  7.         {
  8.             Random numberGenerator = new Random();
  9.             Console.Write("Podaj wielkosc tablicy: ");
  10.             int wielkosc = 0;
  11.             wielkosc = Convert.ToInt32(Console.ReadLine());
  12.             int[] Tablica = new int[wielkosc];
  13.             Console.WriteLine("Jak chcesz wypelnic tablice?\n1. Losowo\n2. Recznie");
  14.             int wybor = 0;
  15.             wybor = Convert.ToInt32(Console.ReadLine());
  16.             switch(wybor)
  17.             {
  18.                 case 1:
  19.                     for (int i = 0; i < wielkosc; i++)
  20.                     {
  21.                         Tablica[i] = numberGenerator.Next(0, 10);
  22.                     }
  23.                     break;
  24.                 case 2:
  25.                     for (int i=0; i<wielkosc; i++)
  26.                     {
  27.                         Console.Write("Podaj " + i + " element tablicy: ");
  28.                         Tablica[i] = Convert.ToInt32(Console.ReadLine());
  29.                     }
  30.                     break;
  31.             }
  32.             for (int i = 0; i < wielkosc; i++)
  33.             {
  34.                 Console.Write(Tablica[i] + " ");
  35.             }
  36.             int max = Tablica[0];
  37.             int min = Tablica[0];
  38.             for (int i=0; i<wielkosc; i++)
  39.             {
  40.                 if(Tablica[i]>max)
  41.                 {
  42.                     max = Tablica[i];
  43.                 }
  44.                 if (Tablica[i]<min)
  45.                 {
  46.                     min = Tablica[i];
  47.                 }
  48.             }
  49.             Console.WriteLine("\nNajwiększy element tablicy: " + max);
  50.             Console.WriteLine("Najmniejszy element tablicy: " + min);
  51.             Console.WriteLine();
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement