Сделать эту программу с циклами while и while.do - C#
Формулировка задачи:
Здравствуйте. Помогите, пожалуйста, написать эту же программу , но с с циклами while и while...do вместо for.
Листинг программы
- int i, j, n;
- float c, sum=0;
- Console.WriteLine("Введите N");
- n = Convert.ToInt32(Console.ReadLine() );
- for (i = 1; i <= n; i++)
- {
- c = i;
- for (j = 2; j <= n - i + 1; j++)
- {
- c *= i;
- }
- sum += c;
- }
- Console.WriteLine("summa = " + sum);
- Console.ReadKey();
Решение задачи: «Сделать эту программу с циклами while и while.do»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int i, j, n;
- float c, sum = 0;
- Console.WriteLine("Введите N");
- n = Convert.ToInt32(Console.ReadLine());
- //for (i = 1; i <= n; i++)
- i = 1;
- while (i <= n)
- {
- c = i;
- //for (j = 2; j <= n - i + 1; j++)
- j = 2;
- while (j <= n - i + 1)
- {
- c *= i;
- j++;
- }
- sum += c;
- i++;
- }
- Console.WriteLine("summa = " + sum);
- Console.ReadKey();
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д