Golang Program to Convert Centimeters into Feet and Inches


Steps

  • Take the height in centimeters and store it in a variable.
  • Convert the height in centimeters into inches and feet.
  • Print the length in inches and feet.
Enter the height in centimeters: 50
The length in inches: 19.7
The length in feet: 1.64
Enter the height in centimeters: 153
The length in inches: 60.28
The length in feet: 5.02

Explanation

  • User must enter the height in centimeters.
  • The height in centimeters is multiplied by 0.394 and stored in another variable which now contains the height in inches.
  • The height in centimeters is multiplied by 0.0328 and stored in another variable which now contains the height in feet.
  • The converted height in inches and feet is printed.

Example

 Live Demo

package main
import "fmt"
func main(){
   var n int
   fmt.Print("Enter the height in centimeters: ")
   fmt.Scanf("%d", &n)
   inches:=0.394*float32(n)
   feet:=0.0328*float32(n)
   fmt.Println("The length in inches:", inches)
   fmt.Println("The length in feet:", feet)
}

Output

Enter the height in centimeters: 50
The length in inches: 19.699999
The length in feet: 1.64

Updated on: 31-Jul-2021

193 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements