how to find maximum value in array
  • Hi how can i find highest value of array in C#.
  • 2 Comments sorted by
  • Vote Up0Vote Down studentstudent
    146.00 Karma Accepted Answer
    Hi this code is for find minimum and maximum value in array.

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

    namespace www.codingresolved.com
    {
    public class Program
    {
    static void Main(string[] args)
    {
    int[] ArrayName = new int[10];
    int Min = 0;
    int Max = 0;

    ArrayName[0] = 15;
    ArrayName[1] = 12;
    ArrayName[2] = 4;
    ArrayName[3] = 9;
    ArrayName[4] = 10;
    ArrayName[5] = 13;
    ArrayName[6] = 25;
    ArrayName[7] = 21;
    ArrayName[8] = 7;
    ArrayName[9] = 18;

    Min = ArrayName[0];

    for (var i = 0; i < ArrayName.Length; i++)
    {
    Console.WriteLine("Number {0,2}:{1, 10}", i + 1, ArrayName[i]);
    }


    for (var i = 0; i < ArrayName.Length; i++)
    {
    if (Min > ArrayName[i])
    Min = ArrayName[i];
    }

    Console.WriteLine();
    Console.WriteLine("Minimum number in Array is = {0}", Min);

    for (int i = 0; i < ArrayName.Length; i++)
    {
    if (Max < ArrayName[i])
    Max = ArrayName[i];
    }

    Console.WriteLine("Maximum number in Array is= {0}\n", Max);
    Console.ReadLine();
    }
    }
    }
  • thanks for code.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative