Factorial means multiplication of 1 to n.
Program for Finding Factorial of a given number
#include<iostream.h>
#include<conio.h>
long int factorial(long int n)
{
long int fact=1;
while ( n > 0)
fact = fact * n--;
return fact;
}
int main( void )
{
lont int num;
cout << " Enter a Number :: ";
cin >> num;
long int res = factorial( num );
cout << "Factorial of " << num << " is " << res;
getch();
return 0;
}
O/P
Enter a Number : 5
Factorial of 5 is 120.
<iframe width="560" height="315" src="https://www.youtube.com/embed/hBJrZr4qnoo" frameborder="0" allowfullscreen></iframe>
General Instructions:
1. Start Turbo - C++
2. Start New File , Press Alt + F, N
3. Type the above code
4. Save your program "factorial.cpp"
5. Compile your program by pressing Alt + F9
6. Run your program by pressing Ctrl + F9
Program for Finding Factorial of a given number
#include<iostream.h>
#include<conio.h>
long int factorial(long int n)
{
long int fact=1;
while ( n > 0)
fact = fact * n--;
return fact;
}
int main( void )
{
lont int num;
cout << " Enter a Number :: ";
cin >> num;
long int res = factorial( num );
cout << "Factorial of " << num << " is " << res;
getch();
return 0;
}
O/P
Enter a Number : 5
Factorial of 5 is 120.
<iframe width="560" height="315" src="https://www.youtube.com/embed/hBJrZr4qnoo" frameborder="0" allowfullscreen></iframe>
General Instructions:
1. Start Turbo - C++
2. Start New File , Press Alt + F, N
3. Type the above code
4. Save your program "factorial.cpp"
5. Compile your program by pressing Alt + F9
6. Run your program by pressing Ctrl + F9
Thanks for Reading my Blog,
Anjeev Singh
Programming and Tricky Maths Guru
YouTube Channel :: https://www.youtube.com/channel/UCTRyQkckpgCNGUUlrqBwvpw
Blog :: https://anjeevsingh.blogspot.in/
Web Site :: www.aneevsingh.co.in
إرسال تعليق