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

n = $stdin.gets.to_i

gets is Kernel.gets which may not always be stdin. Here we refer explicitly to stdin.
#include <stdio.h>
int n;
scanf("%d", &n);

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