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();
}
}
}
0 comments:
Post a Comment