Vous êtes sur la page 1sur 2

C# Programs

largest number

using System;

namespace SimpleCodingQuestions
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(FindLargestNumber(6, 3, 9));
Console.WriteLine(FindLargestNumber(6));
Console.WriteLine(FindLargestNumber(6, 3, 9, 2, 5, 8));
}
public static long FindLargestNumber(long a, params long[]
numbers)
{
// assume that the first value is the biggest
long biggest = a;

// loop through all the arguments passed


foreach (long x in numbers)
{
// check if the current number is the biggest
if (x > biggest)
biggest = x;
}

return biggest;
}
}
}

Vous aimerez peut-être aussi