Сумма квадратов чисел - C#
Формулировка задачи:
Глубокий лес) помогите решить)
Даны целые числа n и m (n < m). Составьте программу, которая вычисляет сумму квадратов чисел от n до m
int n;
Console.WriteLine("Введите число:");
n = Convert.ToInt32(Console.ReadLine());
int m;
Console.WriteLine("Введите число");
m = Convert.ToInt32(Console.ReadLine());
int sum = 0;
int stepen = 0;
for (int i = n; i < m; i++)
{
stepen = 2 * i;
sum += i;
}
Console.WriteLine((double)sum);
Console.ReadKey();Решение задачи: «Сумма квадратов чисел»
textual
Листинг программы
int n;
int m;
Console.WriteLine("Введите число:");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите число");
m = Convert.ToInt32(Console.ReadLine());
int sum = 0;
for (int i = n; i <= m; i++)
{
sum += i * i;
Console.WriteLine(sum);
}
Console.ReadKey();