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

bookПрактика циклу For

Факторіал числа - це добуток усіх чисел від 1 до цього числа. Наприклад, факторіал 5 - це добуток усіх чисел від 1 до 5 (1 x 2 x 3 x 4 x 5), що дає 120.

Чи Знали Ви?

Математичне позначення факторіала - це x!, де x - будь-яке ціле число. Отже, 3! дорівнює 6, 4! дорівнює 24, 5! дорівнює 120 і так далі. Факторіал 0 за визначенням дорівнює 1, тому 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}"); } } }

Initialize the loop variable i with a value of 2 and continue the loop till i is equal to x, so the loop condition will be 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?

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

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

Факторіал числа - це добуток усіх чисел від 1 до цього числа. Наприклад, факторіал 5 - це добуток усіх чисел від 1 до 5 (1 x 2 x 3 x 4 x 5), що дає 120.

Чи Знали Ви?

Математичне позначення факторіала - це x!, де x - будь-яке ціле число. Отже, 3! дорівнює 6, 4! дорівнює 24, 5! дорівнює 120 і так далі. Факторіал 0 за визначенням дорівнює 1, тому 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}"); } } }

Initialize the loop variable i with a value of 2 and continue the loop till i is equal to x, so the loop condition will be 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