C# Function that returns the maximum of three floating-point numbers.

/* C# Function that returns the maximum of three floating-point numbers. */
using System;
public class Demo
{
    public static float max(float a, float b, float c)
    {
        float ans;
        if(a > b && a > c)
            ans = a;
        else if(b > a && b > c)
            ans = b;
        else
            ans = c;
        return ans;
    }

    public static void Main(string[] args)
    {
        float a, b, c, Max = 0;
        Console.WriteLine("Enter 3 values (Floating):");
        a = float.Parse(Console.ReadLine());
        b = float.Parse(Console.ReadLine());
        c = float.Parse(Console.ReadLine());
        Max = max(a, b, c);
        Console.WriteLine("\nMax value is : {0}", Max);
        Console.ReadLine();
    }
}

Output :
Enter 3 value (Floating):
5.2
5.3
5.6

Max value is : 5.600000



Leave a comment