Sat Nov 02 2019

Factorial

C++ Programming3474 views

File Name: factorial.cpp

#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
*/
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.