xxxxxxxxxx
// Program to take input from user using Scanf()
package main
import "fmt"
func main() {
var name string
var age int
// take name and age input using format specifier
fmt.Println("Enter your name and age:")
fmt.Scanf("%s %d", &name, &age)
fmt.Printf("Name: %s\nAge: %d", name, age)
}
xxxxxxxxxx
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)
}
xxxxxxxxxx
// Golang program to illustrate the usage of
// fmt.Scan() function
// Including the main package
package main
// Importing fmt
import (
"fmt"
)
// Calling main
func main() {
// Declaring some variables
var name string
var alphabet_count int
var float_value float32
var bool_value bool
// Calling Scan() function for
// scanning and reading the input
// texts given in standard input
fmt.Scan(&name)
fmt.Scan(&alphabet_count)
fmt.Scan(&float_value)
fmt.Scan(&bool_value)
// Printing the given texts
fmt.Printf("%s %d %g %t", name,
alphabet_count, float_value, bool_value)
}
xxxxxxxxxx
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)
}
xxxxxxxxxx
package main
import ("fmt")
func main() {
var number int
fmt.Scanf("%d", &number) // Input: 10
fmt.Printf("%d", number) // Output: 10
}