Do you want to find the maximum number of an integer array here is C# code to help you to find the maximum number. This code also take care of negative values also.
Please comment in case you have some better solution.
C# Code to find max Number:
using System;
namespace MyApp
{
class my_class
{
static void Main(string[] args)
{
int[] my_number = {-1,10,2};
int max_number = my_number[0];
foreach (int inum in my_number)
{
if (inum > max_number)
{
max_number = inum;
}
}
Console.WriteLine("max number in array: {0}", max_number);
Console.ReadLine();
}
}
}
No comments:
Post a Comment