Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Напишете програма която намира и отпечатва най-големия и най-малкия елемент в масива,
- *както и средно-аритметичната стойност на елементите в него.
- Пример: { 2, 7, 1, 5, 4, 1, 5, 3, 6, 2 }
- Изход: Min = 1 Max = 7 Average = 3.6 */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03_MinMaxAndAverage
- {
- class MinMaxAndAverage
- {
- static void Main()
- {
- int[] array = { 2, 7, 1, 5, 4, 1, 5, 3, 6, 2 };
- int min = array[0];
- int max = array[0];
- int sum = array[0];
- for (int i = 1; i < array.Length; i++)
- {
- int n = array[i];
- if (min > n)
- {
- min = n;
- }
- if (max < n)
- {
- max = n;
- }
- sum += n;
- }
- Console.WriteLine("Minx = {0} , Max = {1} , Average = {2}",min,max,sum / (float)array.Length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment