Decomposition of mathematical functions

Report a typo

As you can see in the code below, two different mathematical processes are represented by the two functions. Try to decompose the repeated pattern in code to another function. Name the new function calculateHalf.

To solve this task, you must not delete or modify any code within the main function. Your only objective is to write the code for the calculateHalf function stated above.

Sample Input 1:

8 12

Sample Output 1:

The result is 10
The result is -2
Write a program in Go
package main

import "fmt"

// calculateHalf prints the result divided by 2
func ? (? ?) {
fmt.Println("The result is", ?)
}

// halfSum sums a and b and then calls calculateHalf to print the result divided by 2
func halfSum(a int, b int) {
calculateHalf(a + b)
}

// halfDifference subtracts b from a then calls calculateHalf to print the result divided by 2
func halfDifference(a int, b int) {
calculateHalf(a - b)
}

// DO NOT delete or modify the code within the main function!
func main() {
var a,b int
fmt.Scanln(&a, &b)
halfSum(a, b)
halfDifference(a, b)
}
___

Create a free account to access the full topic