Завдання: Цикл For
Створити програму, яка обчислює факторіал заданого числа x
за допомогою циклу for. Якщо число дорівнює 0
, програма повинна повертати 1
.
main.cs
12345678910111213141516171819202122232425262728using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int x = 5; int result = ___; if(x == 0) { result = ___; } else { for (___) { result *= ___; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }
Ініціалізувати змінну циклу i
значенням 2
і продовжувати цикл, поки i
не дорівнює x
, тобто умова циклу буде i <= x
.
main.cs
12345678910111213141516171819202122232425262728using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int x = 5; int result = 1; if(x == 0) { result = 0; } else { for (int i = 2; i <= x; i++) { result *= i; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you show me an example of how the program should work with a specific number?
What should the program do if the input is a negative number?
Can you explain why the loop starts at 2 instead of 1?
Awesome!
Completion rate improved to 1.59
Завдання: Цикл For
Свайпніть щоб показати меню
Створити програму, яка обчислює факторіал заданого числа x
за допомогою циклу for. Якщо число дорівнює 0
, програма повинна повертати 1
.
main.cs
12345678910111213141516171819202122232425262728using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int x = 5; int result = ___; if(x == 0) { result = ___; } else { for (___) { result *= ___; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }
Ініціалізувати змінну циклу i
значенням 2
і продовжувати цикл, поки i
не дорівнює x
, тобто умова циклу буде i <= x
.
main.cs
12345678910111213141516171819202122232425262728using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int x = 5; int result = 1; if(x == 0) { result = 0; } else { for (int i = 2; i <= x; i++) { result *= i; } } Console.WriteLine($"Factorial of {x} is {result}"); } } }
Дякуємо за ваш відгук!