The source code to print the table of the given number using the goto statement is given below. The given program is compiled and executed successfully.
// Golang program to print the table of the given number
// using GOTO statement.
package main
import "fmt"
func main() {
var val int = 0
var num int = 0
fmt.Print("Enter Number: ")
fmt.Scanf("%d", &num)
XYZ:
val = val + 1
fmt.Printf("%d*%d=%d\n", num, val, num*val)
if val < 10 {
goto XYZ
}
}
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 the main() function, we created two variables val, num that are initialized with 0 and created a label XYZ.
After that increase the value of variable val by 1 till it becomes 10.
fmt.Printf("%d*%d=%d\n",num,val,num*val)
The above statement will print the calculated number each time on the console screen,
if (val<10){
goto XYZ
}
The above code will transfer program control to the XYZ label if the value of variable val is less than equal to 10.
Program/Source Code:
The source code to print the table of the given number using the goto statement 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 the main() function, we created two variables val, num that are initialized with 0 and created a label XYZ.
After that increase the value of variable val by 1 till it becomes 10.
The above statement will print the calculated number each time on the console screen,
The above code will transfer program control to the XYZ label if the value of variable val is less than equal to 10.
need an explanation for this answer? contact us directly to get an explanation for this answer