How to Find the Greatest Number in Array in C#

This is the simple C# exercise for beginners to understand the arrays. The program will find out the greatest number in a given array e.g. in array [2,34,23,75,8,10] = 75 will be the greatest number.

Source Code 


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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int min = 0; int max = 0; int num;
Console.WriteLine("Enter the number count : ");
int n;
n = Convert.ToInt32(Console.ReadLine()); ;
Console.WriteLine("");
num = Convert.ToInt32(Console.ReadLine()); ;
min = num;
for (int i = 1; i < n; i++)
{
num = Convert.ToInt32(Console.ReadLine()); ;
if (num > max)
{
max = num;
}
if (num < min)
{
min = num;
}
}
Console.WriteLine("");
Console.WriteLine("Greatest is : " + max);
int toPause;
toPause = Console.Read();

}
}
}

Output of the Program

Find the Greatest in Array of Numbers in C#



Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment