Advertisement
tvarbanov

CSharp2-03-02

Jan 3rd, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2.  
  3. class GetMaxMethod
  4. {
  5.     /*Write a method GetMax() with two parameters that returns the bigger of two integers.
  6.      *Write a program that reads 3 integers from the console and prints the biggest of them using the method GetMax().*/
  7.  
  8.     static int GetMax(int firstNum, int secondNum)
  9.     {
  10.         //Returns the bigger number
  11.         if (firstNum>secondNum)
  12.         {
  13.             return firstNum;
  14.         }
  15.         else
  16.         {
  17.             return secondNum;
  18.         }
  19.     }
  20.  
  21.     static void Main()
  22.     {
  23.         //Get the numbers
  24.         Console.Write("Enter the first number : ");
  25.         int firstNum = int.Parse(Console.ReadLine());
  26.         Console.Write("Enter the second number : ");
  27.         int secondNum = int.Parse(Console.ReadLine());
  28.         Console.Write("Enter the third number : ");
  29.         int thirdNum = int.Parse(Console.ReadLine());
  30.  
  31.         //Get the biggest calling the method twice - first compare first two numbers,returns the bigger one and then compares it with the third
  32.         Console.WriteLine("Biggest num is : {0}",GetMax(GetMax(firstNum,secondNum),thirdNum));
  33.  
  34.  
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement