Factorial of number in C++ by R4R Team

Factorial:
-factorial of number is the multiplication of every integer number between 1 and that number.

Example-
factorial of 3 is 6(1*2*3)
factorial of 5 is 120(1*2*3*4*5)


program:

#include < iostream>
using namespace std;
int main()
{
int n,ans=1,i;
cout<<"Enter any numbern";
cin>>n;
for(i=n;i>0;i--)
ans=ans*i;
cout<<"Factorial is: "<< ans;
return 0;
}


output-

Enter any number
5
Factorial is: 120

Enter any number
4
Factorial is: 24

Enter any number
6
Factorial is: 720

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!