Answer to Question #295221 in C# for playhard

Question #295221

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.


1
Expert's answer
2022-02-08T10:17:32-0500


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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS