0

I want to write a program that gets 3 numbers and shows the biggest,smallest, and average. Can someone help?

3rd Nov 2016, 8:11 AM
Mohamad Reza Hajighasem
Mohamad Reza Hajighasem - avatar
7 Answers
+ 5
using System; using System.Linq; class Program { static void Main(string[] args) { int[] numbers = { 3, 9, 5 }; int biggestNumber = numbers.Max(); Console.WriteLine(biggestNumber); Console.ReadLine(); } }
3rd Nov 2016, 8:23 AM
Sandeep Balachandran
Sandeep Balachandran - avatar
+ 1
You are welcome. If you liked the answer, you can leave tumbs up â˜ș
3rd Nov 2016, 10:33 AM
Simone Trombiero
+ 1
Yes, for sure. In this algorithm the average is the medium value, the value that is not max or min. An idea for extend this algorithm for an array of length n is calculate max, min, and calculate average by the sum of all elements of the array divided by n.
3rd Nov 2016, 12:11 PM
Simone Trombiero
0
i want the user to pick the numbers
3rd Nov 2016, 8:26 AM
Mohamad Reza Hajighasem
Mohamad Reza Hajighasem - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Proj { class Program { static void Main(string[] args) { int[] a=new int[3]; for (int i = 0; i < 3; i++) { Console.WriteLine("Enter numer " + (i + 1) + " :"); a[i] = Convert.ToInt32(Console.ReadLine()); } int max = a[0]; int min = a[0]; for (int i = 0; i < 3; i++) { if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; } int av=0; for (int i = 0; i < 3; i++) if (a[i] != max && a[i] != min) av = a[i]; Console.WriteLine("Max: " + max + ", min: " + min + ", average: " + av); Console.Read(); } } }
3rd Nov 2016, 9:14 AM
Simone Trombiero
0
thx
3rd Nov 2016, 10:28 AM
Mohamad Reza Hajighasem
Mohamad Reza Hajighasem - avatar
0
How does the averaging algorithm work? Did it work because there are only 3 elements in the array?
3rd Nov 2016, 11:31 AM
Jos
Jos - avatar