C# program to find maximum and minimum element in array

Introduction :

Write a C# program to input elements in an array from user, find maximum and minimum element in array. C program to find biggest and smallest elements in an array. Logic to find maximum and minimum element in array in C# programming.

C# program to find maximum and minimum element in array :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace array_maximum
{
    class Program
    {
        static void Main(string[] args)
        {
            int d;
            int n;
            float large, small;
            int[] x= new int[40];
            Console.WriteLine("Enter the size of the Array");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the array elements");
            for (int i = 0; i < n; i++)
            {        
                 x[i]= int.Parse(Console.ReadLine());
            }
            Console.Write("");
            large = x[0];
            small = x[0];
            for (int i = 1; i < n; i++)
            {
                if (x[i] > large)
                    large = x[i];
                else if (x[i] < small)
                    small = x[i];
            }
            Console.WriteLine("Large element in array  {0}", large);
            Console.WriteLine("Small element in  array {0}", small);
        }
    }
}

OutPut of Program :

C# program to find maximum and minimum element in array

 

Learn Recommended posts :

2 Comments

Leave a Reply

Your email address will not be published.