C# Program to find the Factorial of a Number using For Loop

preview_player
Показать описание
In this video you will learn to write a C# Program to find the factorial of a number using For Loop ( Iterative Method ).

The factorial of a positive integer n, which is denoted as n!, is the product of all positive integers less than or equal to n.

That is n! = n * (n-1)*(n-2)*....*3*2*1

So 4! = 4 * 3 * 2 * 1 which is equal to 24.

Factorial for the numbers 0 and 1 is 1. That is 0! = 1 and 1! = 1. For negative numbers factorial value doesn't exists.

C# Program to Find the Factorial of a number using Recursion ( Recursive Method )

Get the Source Code of this tutorial at

our Social Media Pages

#CSharpProgramming #ExampleProgram
Рекомендации по теме
Комментарии
Автор

Your detailed explanation of the "for( int counter = . . . )" statement is much appreciated!

James-hebu
Автор

Your explanation made much more sense than the code I had in front of me to be honest! Thanks a lot!

Console.Write("Enter a number: ");
var number =

var factorial = 1;
for (var i = 1; i <= number; i++)
factorial = factorial * i;

Console.WriteLine("{0}! = {1}", number, factorial);

gravydiet
Автор

Thanks Bro! very detailed, helps a lot for a beginner like me.

nichoanton
Автор

Hey!
Thank you so much for the detailed explanation, I have an question! Is there any way to show the process of the factorial?
So, for example if I wanted to get the factorial of the number 3!
The output would look something like this!
1*1=1
1*2=2
2*3=6
and so forth!

adriansfreimanis
welcome to shbcf.ru