Answer to Question #265815 in C++ for Urooj

Question #265815

The factorial of a number is the function that multiplies the number by every natural number below it example 4! = 4*3*2*1 = 24

Write a code to find the factorial of a number given by the user 


1
Expert's answer
2021-11-14T09:20:51-0500
#include<iostream>
using namespace std;
int main(){
	cout<<"Enter a number:  "<<endl;
	int n;
	cin>>n;
	int fact = 1;
	for(int i=1; i<=n; i++){
		fact *= i;
	}
	cout<<"Factorial of "<<n<<" is "<<fact<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS