Overflow with math operations

Report a typo

John has created a calculator that works only with int8 variables. Before executing math operations, he needs to know if the result will have an overflow. Check three operations: "+", "-", and "*" for possible overflow with given numbers.

Remember that when using the int type, we won't have overflow with numbers from the int8 range, because the int type has a much bigger range. To check the overflow, you need to perform an operation first with the int8 values, then with the int values, and finally compare their values. If they are different, we have an overflow.

Sample Input 1:

125
125

Sample Output 1:

+
*
Write a program in Go
package main

import "fmt"

func main() {
var num1, num2 int8
fmt.Scan(&num1, &num2)

if int(? + ?) != int(?) + int(?) {
fmt.Println("+")
}

// add the same checks for "-" and "*" below:
}
___

Create a free account to access the full topic