Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AverageValue
- {
- class IntArray
- {
- int[] intArray = new int[5];
- public int this[int index]
- {
- get
- {
- return intArray[index];
- }
- set
- {
- intArray[index] = value;
- }
- }
- int average;
- public int Average
- {
- get
- {
- return average;
- }
- }
- int total;
- public int Total
- {
- get
- {
- return total;
- }
- }
- public void AverageAndTotal()
- {
- int i;
- total = 0;
- for (i = 0; i < intArray.Length; i++)
- {
- total += intArray[i];
- }
- average = total/ intArray.Length;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int i;
- IntArray firstObject = new IntArray();
- Console.WriteLine("Введите массив:");
- for (i = 0; i < 5; i++)
- {
- Console.Write("{0} элемент массива: ", i + 1);
- firstObject[i] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine("\nБыл введен массив:");
- for (i = 0; i < 5; i++)
- {
- Console.Write(" {0}", firstObject[i]);
- }
- firstObject.AverageAndTotal();
- Console.WriteLine("\n\nСреднее арифметическое элементов массива: {0}", firstObject.Average);
- Console.WriteLine("Сумма элементов массива: {0}", firstObject.Total);
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement