3
21/10/2024 6:50 pm
Emne starter
Write a program that reads from the console a sequence of n integer numbers and returns the minimal, the maximal number, the sum and the average of all numbers (displayed with 2 digits after the decimal point). The input starts by the number n (alone in a line) followed by n lines, each holding an integer number. The output is like in the examples below.
Examples:
1 Answer
2
21/10/2024 6:51 pm
Very good share - as this is very important task to understand! Here is my code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class MinMaxSumAndAverageOfNNumbers { static void Main() { int n = int.Parse(Console.ReadLine()); int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = int.Parse(Console.ReadLine()); } Console.WriteLine("min = {0}", array.Min()); Console.WriteLine("max = {0}", array.Max()); Console.WriteLine("sum = {0}", array.Sum()); Console.WriteLine("avg = {0:F2}", array.Average()); } }