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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...