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

Program is not meant to add up all the numbers. You\'d input numbers in the array. For example 12, 13, 14, 5, 11, since 14 is the largest number in the array, the program would output to console 14.

Solution

using System.IO;
using System;

class Program
{
//method to find largest element of the array
public static int Max(int[] array){
int max = array[0];
//finding maximum
for(int i=1;i<array.Length;i++)
{

if (array[i] > max)
max = array[i];
  

  
}
return max;
}
static void Main()
{int n;
int max;
//prompting user for entering size and elements of the array
Console.WriteLine(\"Enter size of the array : \");
n= Convert.ToInt32(Console.ReadLine());
int[] array = new int[n];
Console.WriteLine(\"Enter elements of the array : \");
for(int i=0;i<n;i++)
array[i] = Convert.ToInt32(Console.ReadLine());
//calling max function
max=Max(array);
Console.WriteLine(\"Largest element in the array : {0} \",max);
  
}
}

/******OUTPUT**********
Enter size of the array :   
5   
Enter elements of the array :   
12
3   
14
15
11
Largest element in the array : 15
**********OUTPUT********/
/This code has been tested on c# compiler,Please ask in case of any doubt,Thanks.

Write a C# program with, public static Max(int[] array) that prints the maximum value found in \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site