Golang program to create a user-defined function to add two integer numbers
belongs to collection: Golang User-defined Function Programs
All Answers
total answers (1)
belongs to collection: Golang User-defined Function Programs
total answers (1)
Program/Source Code:
The source code to create a user-defined function to add two integer numbers is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.
In this program, we created a user defined function addition(), which is given below:
The addition() function will accept two integer numbers and return the sum of both numbers to the calling function.
In the main() function, we created three variables num1, num2, which are initialized with 0. Then we read the value of num1, num2 from the user and we got the sum of both numbers by calling the addition() function and assigned it to the result variable. After that, we printed the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer