How to Read and Print an Integer value in C

05 Dec, 2018
The given task is to take an integer as input from the user and print that integer in C language.
In below program, the syntax and procedures to take the integer as input from the user is shown in C language.
Steps:
The user enters an integer value when asked.This value is taken from the user with the help of scanf() method. The scanf() method, in C, reads the value from the console as per the type specified.Syntax:scanf("%X", &variableOfXType);

where %X is the format specifier in C
It is a way to tell the compiler 
what type of data is in a variable 

and

& is the address operator in C,
which tells the compiler to change the 
real value of this variable, stored at this 
address in the memory.
For an integer value, the X is replaced with type int. The syntax of scanf() method becomes as follows then:Syntax:scanf("%d", &variableOfIntType);
This entered value is now stored in the variableOfIntType.Now to print this value, printf() method is used. The printf() method, in C, prints the value passed as the parameter to it, on the console screen.Syntax:printf("%X", variableOfXType);
For an integer value, the X is replaced with type int. The syntax of printf() method becomes as follows then:Syntax:printf("%d", variableOfIntType);
Hence, the integer value is successfully read and printed.
The user enters an integer value when asked.
This value is taken from the user with the help of scanf() method. The scanf() method, in C, reads the value from the console as per the type specified.Syntax:scanf("%X", &variableOfXType);

where %X is the format specifier in C
It is a way to tell the compiler 
what type of data is in a variable 

and

& is the address operator in C,
which tells the compiler to change the 
real value of this variable, stored at this 
address in the memory.

Syntax:
scanf("%X", &variableOfXType);

where %X is the format specifier in C
It is a way to tell the compiler 
what type of data is in a variable 

and

& is the address operator in C,
which tells the compiler to change the 
real value of this variable, stored at this 
address in the memory.

For an integer value, the X is replaced with type int. The syntax of scanf() method becomes as follows then:Syntax:scanf("%d", &variableOfIntType);

Syntax:
scanf("%d", &variableOfIntType);

This entered value is now stored in the variableOfIntType.
Now to print this value, printf() method is used. The printf() method, in C, prints the value passed as the parameter to it, on the console screen.Syntax:printf("%X", variableOfXType);

Syntax:
printf("%X", variableOfXType);

For an integer value, the X is replaced with type int. The syntax of printf() method becomes as follows then:Syntax:printf("%d", variableOfIntType);

Syntax:
printf("%d", variableOfIntType);

Hence, the integer value is successfully read and printed.
Program:
C
// C program to take an integer// as input and print it  #include <stdio.h>  int main(){      // Declare the variables    int num;      // Input the integer    printf("Enter the integer: ");    scanf("%d", &num);      // Display the integer    printf("Entered integer is: %d", num);      return 0;}
Output:
Enter the integer: 10
Entered integer is: 10

C Basics
C Language
School Programming
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Substring in C++
Function Pointer in C
Left Shift and Right Shift Operators in C/C++
Different Methods to Reverse a String in C++
std::string class in C++
Python Dictionary
Reverse a string in Java
Introduction To PYTHON
Interfaces in Java
Inheritance in C++