Logo

Programming-Idioms

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

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
#include <stdio.h>
int n[15];
fgets(n, 15, stdin);
#include <stdio.h>
int n;
scanf("%d", &n);
(def n (Integer/parseInt (read-line)))
IDENTIFICATION DIVISION.
PROGRAM-ID. stdin.
PROCEDURE DIVISION.
    ACCEPT n
STOP RUN.
#include <iostream>
std::cin >> n;
using System;
n = int.Parse(Console.ReadLine());
import std.stdio;
readf("%d", &n);
import 'dart:io';
String? s = stdin.readLineSync();  
int? n = int.tryParse(s ?? "");
n = String.to_integer IO.gets ""
   integer :: n
   read (*,*) n
import "fmt"
_, err := fmt.Scanf("%d", &n)
import "fmt"
_, err := fmt.Scan(&n)
n <- (read :: String -> Int) <$> getContents
const {createInterface} = require('readline')

const rl = createInterface ({
  input: process.stdin,
  output: process.stdout
})

rl.question('Input an integer: ', response => {
  let n = parseInt (response)
  // stuff to be done with n goes here

  rl.close()
})
import java.util.Scanner;
Scanner in = new Scanner(System.in);
n = in.nextInt();
n = io.read("n")
scanf("%d",&n);
fscanf(STDIN, "%d\n", $n);
read(n);
my $n = <> + 0;  # read a line from STDIN, add 0 to convert to int
n = int(input("Input Prompting String: "))
n = $stdin.gets.to_i
use std::io;
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let n: i32 = input.trim().parse().unwrap();
use std::io::BufRead;
let n: i32 = std::io::stdin()
    .lock()
    .lines()
    .next()
    .expect("stdin should be available")
    .expect("couldn't read from stdin")
    .trim()
    .parse()
    .expect("input was not an integer");
fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer
}

let n = get_input().trim().parse::<i64>().unwrap();
#[macro_use] extern crate text_io;
let n: i32 = read!();