Home > Back-end >  For help on how to handle data overflow information
For help on how to handle data overflow information

Time:06-10

After returning to write factorial n today! Recursive programs, but requirements: 1, you need to determine whether the entered n less than zero, if less than zero, prompt illegal, interrupt program; 2. To determine whether a result more than the data types used to store the results given by the largest range of storage, for example, if a given result is unsigned long, then the result can't more than the type of maximum range, otherwise prompt results overflow,

CodePudding user response:

Unsigned long I; I=0 and 1; Is the maximum

CodePudding user response:

If direct use unsigned long to put n! Result, may not be very good to control overflow, also can, of course, the last n! If value is overflow, the possible ratio (n - 1)! The small
In order to insurance, it is suggested that if use unsigned long to determine whether overflow, can consider to use unsigned long long memory n! The maximum value, and then with the unsigned long, if is greater than the maximum value, that is overflow,

For your reference ~

CodePudding user response:

All kinds of numerical maximum minimum
https://en.cppreference.com/w/c/types/limits

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related