Basic Programming C# Examples

C# Program to Check largest Number among given integers

The Program in C# Program to Check largest Number among given integers is given below:

using System;

namespace LargestNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family, enter the number of integers  here you want to compare:");
            int n = Convert.ToInt32(Console.ReadLine());

            int[] numbers = new int[n];
            Console.WriteLine("Enter the integers:");
            for (int i = 0; i < n; i++)
            {
                numbers[i] = Convert.ToInt32(Console.ReadLine());
            }

            int largest = numbers[0];
            for (int i = 1; i < n; i++)
            {
                if (numbers[i] > largest)
                {
                    largest = numbers[i];
                }
            }

            Console.WriteLine("Okay, the largest number is: " + largest);
            Console.ReadLine();
        }
    }
}

Output:


Hello Codeauri Family, enter the number of integers here you want to compare:
Enter the integers:

20540707

20560423
20120292
Okay, the largest number is: 20560423

Pro-Tips💡

Here are the step by step execution of above program:

  1. The program starts with the line using System;, which is a directive that includes the System namespace. This namespace contains many classes and methods that are commonly used in C# programs, including the Console class that is used later in the program.
  2. The next line namespace LargestNumber defines a namespace for the program, which can be used to organize related classes and avoid naming conflicts with other classes.
  3. The following block class Program defines a class called Program that contains the program logic.
  4. The method Main(string[] args) is the entry point of the program. This method will be executed when the program is run.
  5. The line Console.WriteLine("Hello Codeauri Family, enter the number of integers here you want to compare:"); outputs the text “Hello Codeauri Family, enter the number of integers here you want to compare:” to the console.
  6. The next line int n = Convert.ToInt32(Console.ReadLine()); reads a line of text from the console and converts it to an integer, which is stored in the variable n.
  7. The line int[] numbers = new int[n]; creates an array of integers with n elements.
  8. The following loop for (int i = 0; i < n; i++) prompts the user to enter n integers. The entered integers are stored in the numbers array.
  9. The next block of code for (int i = 1; i < n; i++) loops through the numbers array and keeps track of the largest number. The variable largest is initialized with the first element of the numbers array. The loop then checks if each subsequent element is larger than largest, and if so, updates largest with the new largest number.
  10. The line Console.WriteLine("Okay, the largest number is: " + largest); outputs the text “Okay, the largest number is: ” followed by the largest number that was found in the previous step.
  11. The last line Console.ReadLine(); waits for the user to press the Enter key before closing the console.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

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

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X