codescracker


c++

C++ Program to Find Factorial of Number



« Previous Program Next Program »


Find Factorial of Number in C++

To find factorial of a number in C++ programming, you have to ask to the user to enter the number to find the factorial of the number using the for loop and display the factorial result of the number on the output screen as shown here in the following program.

C++ Programming Code to Find Factorial of Number

Following C++ program ask to the user to enter a number to find its factorial, then display the result on the screen :

/* C++ Program - Find Factorial of Number */

#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, i, fact=1;
	cout<<"Enter a number : ";
	cin>>num;
	for(i=num; i>0; i--)
	{
		fact=fact*i;
	}
	cout<<"Factorial of "<<num<<" is "<<fact;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program find factorial of number

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test