Write a C program with public static Maxint array that print
Write a C# program with, public static Max(int[] array) that prints the maximum value found in \"array.\"
Example input: 12, 3, 14, 5, 11
Example output: 14
Solution
Please follow the cod eand comments for description :
CODE :
using System.IO; // required data to be used
using System;
namespace MaxOfArray // namespace
{
public static class Program // class to run the code
{
public static void Main(string[] args) // driver method
{
int[] array = new int[10]; // initialise an array
Console.WriteLine(\"Please Enter the Array Elements to be Inserted : \"); // prompt for the user
for(int i = 0; i < 10; i++) // iterate over the data
{
array[i] = Convert.ToInt32(Console.ReadLine()); // get the data
}
Max(array); // call the method by passing the array
}
public static void Max(int[] array) { // method declaration and initialisation
int largest = array[9]; // random value
for(int i = 0; i < 10; i++) // iterate over the data
{
if (array[i] > largest) // check for the value
{
largest = array[i]; // save the data
}
}
Console.WriteLine(\"The Largest Number is : {0}.\", largest); // message to the user
}
}
}
OUTPUT :
Please Enter the Array Elements to be Inserted :
15
65
98
41
23
57
42
62
25
32
The Largest Number is : 98.
Hope this is helpful.
![Write a C# program with, public static Max(int[] array) that prints the maximum value found in \ Write a C# program with, public static Max(int[] array) that prints the maximum value found in \](/WebImages/42/write-a-c-program-with-public-static-maxint-array-that-print-1130606-1761603914-0.webp)