You are on page 1of 2

Write a program to find out and print the maximum value in

an array.
06 August 2023 19:46

1 // Write a program to find out and print the maximum value in an


2 array.
3
4
5 int[] values = new int[5];
6 int counter = 1;
7
8
9 for (int i = 0; i < 5; i++)
10 {
11 Console.Write(counter + ". Enter a value: ");
12 values[i] = Convert.ToInt32(Console.ReadLine());
13 counter++;
14 }
15
16
17 int maxvalue = 0;
18 for (int i = 0;i < 5;i++)
19 {
20 if (values[i] > maxvalue)
21 {
22 maxvalue = values[i];
}
}

Console.WriteLine("\nMaximum Value is: " + maxvalue);

Screenshot:

Result:

Interview Questions Page 1


Interview Questions Page 2

You might also like