anizko

09. Greater of Two Values

Jul 2nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09._Greater_of_Two_Values
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string type = Console.ReadLine();
  10.  
  11.             if (type == "int")
  12.             {
  13.                 int firstElement = int.Parse(Console.ReadLine());
  14.                 int secondElement = int.Parse(Console.ReadLine());
  15.                 Console.WriteLine(FineMaxElement(firstElement, secondElement));
  16.             }
  17.  
  18.             else if (type == "char")
  19.             {
  20.                 char firstElement = char.Parse(Console.ReadLine());
  21.                 char secondElement = char.Parse(Console.ReadLine());
  22.                 Console.WriteLine(FineMaxElement(firstElement, secondElement));
  23.             }
  24.  
  25.             else if (type == "string")
  26.             {
  27.                 string firstElement = Console.ReadLine();
  28.                 string secondElement = Console.ReadLine();
  29.                 Console.WriteLine(FineMaxElement(firstElement, secondElement));
  30.             }
  31.  
  32.            
  33.         }
  34.  
  35.         static string FineMaxElement(string firstElement, string secondElement)
  36.         {
  37.             if (firstElement.CompareTo(secondElement) >= 0)
  38.             {
  39.                 return firstElement;
  40.             }
  41.             else
  42.             {
  43.                 return secondElement;
  44.             }
  45.  
  46.         }
  47.         static char FineMaxElement(char firstElement, char secondElement)
  48.         {
  49.             if (firstElement > secondElement)
  50.             {
  51.                 return firstElement;
  52.             }
  53.             else
  54.             {
  55.                 return secondElement;
  56.             }
  57.  
  58.         }
  59.         static int FineMaxElement(int firstElement, int secondElement)
  60.         {
  61.             return Math.Max(firstElement, secondElement);
  62.         }
  63.  
  64.  
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment