Create a program that will implement methods such as Min (int n1, int n2, int n3)
and Max (int x1, int x2, int x3). The two (2) methods must return an integer smallest (Min)
and integer largest (Max) based on any supplied arguments upon calling.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace App
{
class Program
{
static int Min(int n1, int n2, int n3)
{
if (n1 < n2 && n1 < n3)
{
return n1;
}
if (n2 < n1 && n2 < n3)
{
return n2;
}
return n3;
}
static int Max(int x1, int x2, int x3)
{
if (x1 > x2 && x1 > x3)
{
return x1;
}
if (x2 > x1 && x2 > x3)
{
return x2;
}
return x3;
}
static void Main(string[] args)
{
Console.Write("Enter the value n1: ");
int n1 = int.Parse(Console.ReadLine());
Console.Write("Enter the value n2: ");
int n2 = int.Parse(Console.ReadLine());
Console.Write("Enter the value n3: ");
int n3 = int.Parse(Console.ReadLine());
Console.WriteLine("The smallest number: {0}", Min(n1, n2, n3));
Console.WriteLine("The largest number: {0}", Max(n1, n2, n3));
Console.ReadLine();
}
}
}
Comments
Leave a comment