Среднее арифметическое чисел, заканчивающихся цифрой 3 - C#
Формулировка задачи:
Есть задача:
Ввести с клавиатуры 9 любых чисел. Найти среднее арифметическое тех, заканчивающиеся цифрой 3.
Помогите
Вот что у меня получилось :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d, e, f, g, h, j;
int q, w, r, t, y, u, i, o, p;
int AM=1;
Console.WriteLine("Введіть число 1 =");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 2 =");
b = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 3 =");
c = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 4 =");
d = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 5 =");
e = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 6 = ");
f = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 7 =");
g = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 8 =");
h = int.Parse(Console.ReadLine());
Console.WriteLine("Введіть число 9 =");
j = int.Parse(Console.ReadLine());
q = a % 10;
w = b % 10;
r = c % 10;
t = d % 10;
y = e % 10;
u = f % 10;
i = g % 10;
o = h % 10;
p = j % 10;
if (q == 3)
{
AM = AM / q;
}
if (w == 3)
{
AM = AM / w;
}
if (r == 3)
{
AM = AM / r;
}
if (t == 3)
{
AM = AM / t;
}
if (y == 3)
{
AM = AM / y;
}
if (u == 3)
{
AM = AM / u;
}
if (i == 3)
{
AM = AM / i;
}
if (o == 3)
{
AM = AM / o;
}
if (p == 3)
{
AM = AM / p;
}
Console.WriteLine(+AM);
}
}
}Решение задачи: «Среднее арифметическое чисел, заканчивающихся цифрой 3»
textual
Листинг программы
int value = 0;
int sum = 0;
int count = 0;
for (int idx = 0; idx < 9; ++idx)
{
Console.Write("Введите {0} число: ", (idx + 1));
value = int.Parse(Console.ReadLine());
if ((value % 10) == 3)
{
count++;
sum += value;
}
}
if (count != 0)
{
Console.WriteLine("Среднее чисел, оканчивающихся на 3, равно {0}", (sum / count));
}
else Console.WriteLine("Числа, оканчивающиеся на 3, отсутствуют");