C# Function which returns the smaller of its two parameters.

/* C# Function which returns the smaller of its two parameters. */
using System;
public class Demo
{
    public static int min(int a, int b)
    {
        int min_val = 0;
        if(a < b)
            min_val = a;
        else
            min_val = b;
        return min_val;
    }

    public static void Main(string[] args)
    {
        int a, b, val;
        Console.WriteLine("Enter 2 number : \n");
        a = Convert.ToInt32(Console.ReadLine());
        b = Convert.ToInt32(Console.ReadLine());
        val = min(a, b);
        Console.WriteLine("Smaller value is : {0}", val);
        Console.ReadLine();
    }
}

Output :
Enter 2 number :
50
80
Smaller value is : 50



Leave a comment