Factorial Of Number Using C++ Programming Language

Q: How to calculate Factorial of given number using C++ Programming Language?

Solution: 
Factorial:
4! = 4 * 3 * 2 * 1 = 24
This is how the the factorial of given number is obtained
Lets write our C++ Program to calculate factorial of given number using C++ Programming language,A user will enter the number , and our program will calculate it.



Program code:
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int i , fact = 1 ;
cout<< "Enter a number whose Factorial is to be calculate "<<endl <<endl;
cin >> i;
cout<<endl;
while(i > 0)
{
fact= fact * i ;
i--;

}

     cout<<endl;
cout<<"Factorial of given number is  =  " << fact ;

getch();


}

Output: after compiling and executing the output of program will like this


Hope that you will find this helpful.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.