0
Maximum and Minimum array method help please
Write a program to take 5 numbers as input, then calculate and output the sum of the maximum and the minimum inputted values. Sample Input 5 6 14 2 1 Sample Output 15 Explanation The minimum value is 1, the maximum is 14. So 14+1 = 15 should be output. Hint Create an array, use while loop to store the inputted numbers in it, and then do the calculations.
4 Antworten
+ 7
Left 4 Bread
It is very simple. Just do this
int[] arr = new int[5];
int i = 0;
while (i < 5) {
arr[i] = Convert.ToInt32(Console.ReadLine());
i++;
}
Console.Write(arr.Min() + arr.Max());
+ 1
🅰🅹 🅐🅝🅐🅝🅣 it worked! Thank you very much!
0
Here is what i have so far. I know it says use a while loop but ive been stumped. Any help is welcome.
//here is what i have with a while loop
/*
while (numbers <=5)
{
Console.WriteLine(arr.Max() + arr.Min());
}
*/
class Program
{
static void Main(string[] args)
{
//array declaration
int [] arr = new int [5];
// array methods
int sum = arr.Min() + arr.Max();
// user input
int numbers = Convert.ToInt32(Console.ReadLine());
// solution attempt
foreach (int k in arr)
{
Console.WriteLine(arr[numbers]);
}
0
Thank you 🅰🅹 🅐🅝🅐🅝🅣 I’ll give it a try