C++ Programming

Factorial

C plus plus for factorial calculation

11/2/2019
0 views
factorial.cppCPP
#include<iostream>
using namespace std;

int main() {
	long int f = 1, no;
	cout << "Program to calculate factorial" << endl;
	cout << "Enter a number:" << endl;
	cin >> no;

	/* Loop the process using "Do While Loop" */
	do {
		f = no * f;
		no = no - 1;
	}
	while(no >= 1);
	cout << "Factorial: " << f << endl;
	return 0;
}



/* Output */
/*
Program to calculate factorial
Enter a number:
5

Factorial: 120
*/
cppc plus plusfactorial

Related Examples