Math operations with long long in c
问题 Given long long x , long long y , and int z , how can trunc(( x + y + z )/3) be calculated using fully defined operations in C but excluding unsigned long long and wider arithmetic? (trunc( x ) is “rounding toward zero”: It is x if x is an integer and otherwise is the next integer toward zero.) 回答1: You can calculate the average of two integers x and y without the risk of overflow as follows (pseudocode): int average = (x and y have the same sign) ? x + (y - x) / 2 : (x + y) / 2; This is not