![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Find Factorial of Large Numbers
The following is an example to find the factorial.
Example
#include <iostream> using namespace std; int fact(unsigned long long int n) { if (n == 0 || n == 1) return 1; else return n * fact(n - 1); } int main() { unsigned long long int n; cout<<"Enter number : "; cin>>n; cout<< “\nThe factorial : “ << fact(n); return 0; }
Output
Enter number : 19 The factorial : 109641728
In the above program, we have declared a variabe with the following data type for large numbers.
unsigned long long int n;
The actual code is in fact() function as follows −
int fact(unsigned long long int n) { if (n == 0 || n == 1) return 1; else return n * fact(n - 1); }
In the main() function, a number is entered by the user and fact() is called. The factorial of entered number is printed.
cout<<"Enter number : "; cin>>n; cout<<fact(n);
Advertisements