Created
October 21, 2014 15:59
-
-
Save IvanNikolov/99d9d48f1329edab5896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
//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: | |
//input output | |
// 3 min = 1 | |
// 2 max = 5 | |
// 5 sum = 8 | |
// 1 avg = 2.67 | |
class MinMaxSumAverageOfNNumbers | |
{ | |
static void Main() | |
{ | |
int n = int.Parse(Console.ReadLine()); | |
List<int> numbers = new List<int>(n); | |
for (int i = 0; i<n; i++) | |
{ | |
Console.WriteLine("Please enter number"); | |
numbers.Add(int.Parse(Console.ReadLine())); | |
} | |
int min = int.MinValue; | |
int max = int.MinValue; | |
int sum = 0; | |
int ave = 0; | |
foreach (var item in numbers) | |
{ | |
min = Math.Min(min, item); | |
max = Math.Max(max, item); | |
ave = sum / n; | |
sum = sum + item; | |
} | |
Console.WriteLine(min+"\n"+max+"\n"+sum+"\n"+ave); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment