In: Computer Science
DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read from the user. Document your code and properly label the input prompts and the outputs as shown below. Sample run 1: You entered: 20, 8, 12 Max value: 20 Min value: 8 Average value: 13 Sample run 2: You entered: 1, 2, 3 Max value: 3 Min value: 1 Average value: 2 Sample run 3: You entered: 10, 5, 25 Max value: 25 Min value: 5 Average value: 13
using System; public class MinMaxAvg { static int min(int x, int y, int z) { int value = x; if (y < value) { value = y; } if (z < value) { value = z; } return value; } static int max(int x, int y, int z) { int value = x; if (y > value) { value = y; } if (z > value) { value = z; } return value; } static int average(int x, int y, int z) { return (x + y + z) / 3; } public static void Main(string[] args) { Console.Write("Enter first number: "); int n1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter second number: "); int n2 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter third number: "); int n3 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("You entered: " + n1 + ", " + n2 + ", " + n3); Console.WriteLine("Max value: " + max(n1, n2, n3)); Console.WriteLine("Min value: " + min(n1, n2, n3)); Console.WriteLine("Average value: " + average(n1, n2, n3)); } }