Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #120 Read integer from stdin

Read an integer value from the standard input into the variable n

import "fmt"
_, err := fmt.Scanf("%d", &n)
import "fmt"
_, err := fmt.Scan(&n)

Warning: if the input has a leading 0, it will be interpreted as octal!
#include <stdio.h>
int n;
scanf("%d", &n);

New implementation...
< >
programming-idioms.org