Практика циклу 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
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}"); } } }
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
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}"); } } }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 1.59
Практика циклу 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
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}"); } } }
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
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}"); } } }
Дякуємо за ваш відгук!