0
I want to write a program that gets 3 numbers and shows the biggest,smallest, and average. Can someone help?
7 ответов
+ 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();
    }
}
+ 1
You are welcome. If you liked the answer, you can leave tumbs up ☺
+ 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.
0
i want the user to pick the numbers
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();
        }
    }
}
0
thx
0
How does the averaging algorithm work? Did it work because there are only 3 elements in the array?






