Reading Input: bufio

Reading input with fmt.Scan and the & pointers.

Problem data arrives on standard input. The basic way to read in Go is fmt.Scan: it reads values across spaces and newlines. Note the & symbol before the variable: Scan needs to know WHERE to store the value, so it receives the variable's address. A forgotten & is the mistake every beginner makes. Press "Input", enter two numbers and run it.
Go

Enter two numbers in the "Input" field, for example: 3 5

fmt.Scan reads values in order and can fill several variables at once. Words (without spaces) are read into a string the same way.
Go

Enter a name and an age, for example: Azat 15

fmt.Scan is convenient but slow on large inputs — we will cover fast reading via bufio in the last lesson of the course. Task: read three numbers and print their arithmetic mean (don't forget the float64 conversion for a fractional result). Then solve the attached problem "Sum of Two Numbers", get Accepted and mark the lesson as completed.

Practice problems

Доска