Maximum value of an integer for which factorial can be calculated on a machine in C++

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to find maximum value of an integer for which factorial can be calculated on a machine.

For this we will be provided with an integer value. Our task is to find the maximum value of an integer for which factorial can be calculated on a machine without getting converted into a negative value.

Example

 Live Demo

#include <stdio.h>
int findMaxValue() {
   int res = 2;
   long long int fact = 2;
   while (1) {
      if (fact < 0)
         break;
      res++;
      fact = fact * res;
   }
   return res - 1;
}
int main() {
   printf ("Maximum value of integer : %d\n",
   findMaxValue());
   return 0;
}

Output

Maximum value of integer : 20
raja
Published on 27-Jul-2020 12:08:12
Advertisements