C# Program to Find the Largest of Two Numbers

In this example, we’ll create a simple C# program to determine the largest of two given numbers, demonstrating basic comparison operations.

Problem Statement

Write a C# program to find and display the largest of two numbers. The program should take two numeric inputs and determine which one is greater, then display the result as the largest number.

C# Program to Find the Largest of Two Numbers

using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter the first number: ");
        double num1 = Convert.ToDouble(Console.ReadLine());

        Console.Write("Enter the second number: ");
        double num2 = Convert.ToDouble(Console.ReadLine());

        double largest = FindLargest(num1, num2);

        Console.WriteLine("The largest number is: " + largest);
    }

    static double FindLargest(double num1, double num2)
    {
        return num1 > num2 ? num1 : num2;
    }
}

Input / Output

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...