Text: |
ФІО = мирон полищук
Запитання:Реализувати метод,який шукаэ суму елементыв заданого дыйсного масиву!
====================================
ANSWER ====================================
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication6
{
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];
}
Console.WriteLine("Sum = {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];
}
return sum;
}
static void Main(string[] args)
{
zapolnit_masiv();
Console.WriteLine("rez = {0}", rezult());
Console.ReadKey();
}
}
}
END of ANSWER ====================================
|