- Related Questions & Answers
- Maximum trains for which stoppage can be provided in C++
- What is the maximum possible value of an integer in C# ?
- Maximum elements which can be crossed using given units of a and b in C++
- What is the maximum possible value of an integer in Python?
- What is the maximum possible value of an integer in Java ?
- How value of firm is calculated
- Program to find maximum value of k for which we can maintain safe distance in Python
- How can Deep Learning be used for facial recognition in Machine Learning?
- Searching for an integer value in a varchar field in MySQL?
- Maximum bishops that can be placed on N*N chessboard in C++
- Program for factorial of a number in C program
- Find maximum points which can be obtained by deleting elements from array in C++
- Find maximum power of a number that divides a factorial in C++
- Find the minimum and maximum values that can be calculated by summing exactly four of the five integers in JavaScript
- Maximum Number of Events That Can Be Attended in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we need to create a program to find Maximum value of an integer for which factorial can be calculated on a machine in C++.

Factorial of a number is a huge value, as it is the product of all values preceding it. And C++ can handle large values only upto a certain value by using its inbuilt function. We need to find this restriction.

We will simply use the property of data types which is when the numbers exceed the maximum value a negative number is returned.

We will use long long int which is the largest basic data type.

#include <iostream> using namespace std; int calcMaxFactVal(){ int maxVal = 1; long long int maxFactorial = 1; while (true){ if (maxFactorial < 0) return (maxVal - 1); maxVal++; maxFactorial *= maxVal; } return - 1; } int main(){ cout<<"The maximum value of an integer for which factorial can be calculated on machine is "<<calcMaxFactVal(); return 0; }

The maximum value of an integer for which factorial can be calculated on machine is 20

Advertisements