Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Завдання: Цикл For | Цикли
Основи C#

bookЗавдання: Цикл For

Створити програму, яка обчислює факторіал заданого числа x за допомогою циклу for. Якщо число дорівнює 0, програма повинна повертати 1.

main.cs

main.cs

copy
12345678910111213141516171819202122232425262728
using 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

main.cs

copy
12345678910111213141516171819202122232425262728
using 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}"); } } }
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

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

bookЗавдання: Цикл For

Свайпніть щоб показати меню

Створити програму, яка обчислює факторіал заданого числа x за допомогою циклу for. Якщо число дорівнює 0, програма повинна повертати 1.

main.cs

main.cs

copy
12345678910111213141516171819202122232425262728
using 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

main.cs

copy
12345678910111213141516171819202122232425262728
using 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}"); } } }
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 2
some-alt