Q:

Golang program to print the Octal value of numbers from 1 to 100 using the goto statement

belongs to collection: Golang goto Statement Programs

0

In this program, we will print the octal number corresponding to the decimal number from 1 to 100 on the console screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to print the Octal value of numbers from 1 to 100 using goto statement is given below. The given program is compiled and executed successfully.

// Golang program to print the Octal value of numbers
// from 1 to 100 using goto statement

package main

import "fmt"

func main() {

	var val int = 1

XYZ:
	fmt.Printf("%o ", val)
	val = val + 1

	if val <= 100 {
		goto XYZ
	}
}

Output:

1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 
31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 5
7 60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77 100 101 102 103 104 
105 106 107 110 111 112 113 114 115 116 117 120 121 122 123 12
4 125 126 127 130 131 132 133 134 135 136 137 140 141 142 143 144

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 a variable val with an initial value of 1 and created a label XYZ.

After that increase the value of variable val by 1 till it becomes 100 and print corresponding octal values using the "%o" format specifier on the console screen,

if (val<=100){
    goto XYZ
}

The above code will transfer program control to the XYZ label if the value of variable val is less than equal to 100.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Golang program to print the ASCII value of specifi... >>
<< Golang program to print the Hex value of numbers f...