double[] numbers = new double[4];
double sum = 0;
int count = 0;
Console.WriteLine("Please enter four real numbers:");
for (int i = 0; i < 4; i++)
{
Console.Write("Number {0}: ", i+1);
if (double.TryParse(Console.ReadLine(), out double num))
numbers[i] = num;
if (num > 0)
sum += num;
count++;
}
else
Console.WriteLine("Ошибка");
i--;
if (count > 0)
double mean = sum / count;
Console.WriteLine("Среднее арифметическое положительных чисел: " + mean);
Console.WriteLine("НЕТУ ПОЛОЖИТЕЛЬНЫХ.");
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
double[] numbers = new double[4];
double sum = 0;
int count = 0;
Console.WriteLine("Please enter four real numbers:");
for (int i = 0; i < 4; i++)
{
Console.Write("Number {0}: ", i+1);
if (double.TryParse(Console.ReadLine(), out double num))
{
numbers[i] = num;
if (num > 0)
{
sum += num;
count++;
}
}
else
{
Console.WriteLine("Ошибка");
i--;
}
}
if (count > 0)
{
double mean = sum / count;
Console.WriteLine("Среднее арифметическое положительных чисел: " + mean);
}
else
{
Console.WriteLine("НЕТУ ПОЛОЖИТЕЛЬНЫХ.");
}