Algorithm
For Example use the scan()
function to take input from the user
Code Examples
#1 Example- Go Take Input
Code -
Golang Programming
package main
import "fmt"
func main() {
var name string
// takes input value for name
fmt.Print("Enter your name: ")
fmt.Scan(&name)
fmt.Printf("Name: %s", name)
}
Copy The Code &
Try With Live Editor
Output
Name: Akash
#2 Go fmt.Scan()
Code -
Golang Programming
package main
import "fmt"
func main() {
var language string
// takes input value for name
fmt.Print("Enter your favorite language: ")
fmt.Scan(&language)
fmt.Printf("Favorite Language: %s", language)
}
Copy The Code &
Try With Live Editor
Output
#3 Multiple Inputs Using Scan()
Code -
Golang Programming
package main
import "fmt"
func main() {
// create variables
var name string
var age int
// take name and age input
fmt.Println("Enter your name and age:")
fmt.Scan(&name, &age)
// print input values
fmt.Printf("Name: %s\nAge: %d", name, age)
}
Copy The Code &
Try With Live Editor
Output
#4 Go fmt.Scanln()
Code -
Golang Programming
package main
import "fmt"
func main() {
var name string
var age int
// take name and age input
fmt.Println("Enter your name and age:")
fmt.Scanln(&name, &age)
fmt.Printf("Name: %s\nAge: %d", name, age)
}
Copy The Code &
Try With Live Editor
Output
#5 Go fmt.Scanln()
Code -
Golang Programming
package main
import "fmt"
func main() {
var name string
var age int
// take name and age input
fmt.Println("Enter your name and age:")
fmt.Scanln(&name, &age)
fmt.Printf("Name: %s\nAge: %d", name, age)
}
Copy The Code &
Try With Live Editor
Output
Demonstration
Go Take Input-Go Lang Programming