svetlozar_kirkov

GetMax() Exercise

Oct 2nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4.  
  5. namespace ConsoleTesting3
  6. {
  7.     class ConsoleTesting3
  8.     {
  9.         private static void Main()
  10.         {
  11.             Console.Write("Enter integers, separated by space: ");
  12.             var kozle = ReadInput();
  13.             Console.WriteLine("Largest: {0}", GetMax(kozle));
  14.             Console.WriteLine();
  15.             PrintCredits();
  16.             Console.ReadKey();
  17.  
  18.         }
  19.  
  20.         private static void PrintCredits()
  21.         {
  22.             string name = "Svetlozar Valentinov Kirkov";
  23.             foreach (var znak in name)
  24.             {
  25.                 Console.Write(znak);
  26.                 Thread.Sleep(90);
  27.             }
  28.             Console.WriteLine();
  29.         }
  30.  
  31.         private static int[] ReadInput(params int[] inputLine)
  32.         {
  33.             string[] input = Console.ReadLine().Split(' ');
  34.             int[] result = new int[input.Length];
  35.             for (int i = 0; i < result.Length; i++)
  36.             {
  37.                 result[i] = Convert.ToInt32(input[i]);
  38.             }
  39.             return result;
  40.         }
  41.  
  42.         static int GetMax(params int[] nums)
  43.         {
  44.             int maximal = nums[0];
  45.             for (int i = 1; i < nums.Length; i++)
  46.             {
  47.                 if (nums[i] > maximal)
  48.                 {
  49.                     maximal = nums[i];
  50.                 }
  51.             }
  52.             return maximal;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment