Исправте программу пожалуйста. Чтобы при n=0 s тоже оставался 0 - C#
Формулировка задачи:
Исправте программу пожалуйста. Чтобы при n=0 s тоже оставался 0.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Naumenko_lab2_zadanie2 { class Program { static void Main(string[] args) { string N, X; double x, s, a,m; int n, k; Console.WriteLine("Введите количество элементов от 0 до n"); N = Console.ReadLine(); n = Convert.ToInt32(N); Console.WriteLine("Введите значение x"); X = Console.ReadLine(); x = Convert.ToDouble(X); s = 0; k = 0; a = (x - 1) / Math.Pow(x, 2); m = 0; do { s = s + a ; k = k + 1; a = a * (x - 1) / (x + x / k); } while (k + 1 <= n); Console.WriteLine(s); Console.ReadKey(); } } }
Решение задачи: «Исправте программу пожалуйста. Чтобы при n=0 s тоже оставался 0»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Naumenko_lab2_zadanie2 { class Program { static void Main(string[] args) { string N, X; double x, s, a,m; int n, k; Console.WriteLine("Введите количество элементов от 0 до n"); N = Console.ReadLine(); n = Convert.ToInt32(N); Console.WriteLine("Введите значение x"); X = Console.ReadLine(); x = Convert.ToDouble(X); s = 0; k = 0; a = (x - 1) / Math.Pow(x, 2); m = 0; if(n>0)) { do { s = s + a ; k = k + 1; a = a * (x - 1) / (x + x / k); } while (k + 1 <= n); } Console.WriteLine(s); Console.ReadKey(); } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д