C# (sharp) Program to Find Largest Number When Input is taken from User

Here is the code to find the largest number in c sharp program when input is taken from the user using arrays. Change the array size to suit your number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication23
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, largest;
            int[] array = new int[5];
            for (i = 0; i < 5; i++)
            {
                Console.WriteLine(“Enter elements:{0}”, i+1);
                array[i] = Convert.ToInt32(Console.ReadLine());
            }
            largest = array[0];
            for (i = 0; i <5; i++)
            {
                if (array[i] > largest)
                {
                    largest = array[i];
                }
            }
            Console.WriteLine(“The Largest number is :{0}”, largest);
            Console.ReadLine();
        }
        
    }
        }
   

Add Comment