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
#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;
}
Comments
Leave a comment