Find Maximum Number in Array C Sharp Program

By | August 20, 2023

C Sharp Program to find maximum number in array


using System;

namespace FindMax
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[10]; // Array named 'a' to store numbers
            
            Console.WriteLine("Enter 10 numbers:");

            for (int i = 0; i < 10; i++)
            {
                Console.Write("Enter a Number : ");
                a[i] = int.Parse(Console.ReadLine());
            }    

            int max = a[0]; // Assume the first number is the maximum

            for (int i = 1; i < a.Length; i++) 
              { 
               if (a[i] > max)
                  {
                    max = a[i];
                  }
             }

            Console.WriteLine("The maximum number is: "+max);
            Console.ReadKey();        
        }
    }
}

Output:
C Sharp Program to find maximum number in array

C Sharp Program to find maximum number in array

Loading

Leave a Reply

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