Text: |
ФІО = Тмакарчук?
Запитання:ралызувати метод,який пыдраховуэ середне значеня елементив задаеого дыйсного масиву
====================================
ANSWER ====================================
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
const int max = 4;
double[] mas = new double[max];
Console.WriteLine("Vvedite elementi masiva :");
for (int i = 0; i < max; i++)
{
Console.Write("[{0}] = ", i);
mas[i] = Convert.ToDouble(Console.ReadLine());
}
double sum = 0;
for (int i = 0; i < max; i++)
{
sum += mas[i];
}
sum /= max;
Console.WriteLine("ser znach = {0}", sum);
Console.ReadKey();
}
}
}
END of ANSWER ====================================
ANSWER ====================================
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication19
{
class Program
{
const int max = 4;
static double[] mas = new double[max];
static void zapolnit_masiv()
{
Console.WriteLine("Vvedite elementi masiva :");
for (int i = 0; i < max; i++)
{
Console.Write("[{0}] = ", i);
mas[i] = Convert.ToDouble(Console.ReadLine());
}
}
static double rezult()
{
double sum = 0;
for (int i = 0; i < max; i++)
{
sum += mas[i];
}
sum /= max;
return sum;
}
static void Main(string[] args)
{
zapolnit_masiv();
Console.WriteLine("rez = {0}", rezult());
Console.ReadKey();
}
}
}
END of ANSWER ====================================
|