I still working in this exercise all morning and I didn't know how to solution this, can you help me?
Write a program that takes input of an integer N, followed by N integers. The program then outputs the number closest to the average of those N integers. If there are more than one solution, output the one that comes first in the input list.
Your output lines should not have any trailing or leading whitespaces In case of error your output should be 0
Input
5
1 2 3 4 6
Output
3
Explanation: The average is 2.67 for {1,2,3,4,6}. Hence 3 is the closest
The code I have to do:
using System;
public class Test
{
public static void Main()
{
string input = Console.ReadLine();
Console.WriteLine(input);
}
}
Aucun commentaire:
Enregistrer un commentaire