C Program to Print an Integer (Entered by the User) #2

C Program to Print an Integer (Entered by the User)

In this program, integer entered by the user is stored in a variable. Then, that variable is displayed on the screen using printf() function.
Display data entered by the user
To understand this example, you should have the knowledge of following C programming topics:
  • C Programming Constants and Variables
  • C Programming Data Types
  • C Input-Output (I/O)

Program to Print an Integer

#include <stdio.h>
int main()
{
    int number;

    // printf() dislpays the formatted output 
    printf("Enter an integer: ");  
    
    // scanf() reads the formatted input and stores them
    scanf("%d", &number);  
    
    // printf() displays the formatted output
    printf("You entered: %d", number);
    return 0;
}
Output
Enter a integer: 25
You entered: 25
In this program, an integer variable number is declared.
The printf() function displays Enter an integer: on the screen. Then, the scanf()function reads an integer data from the user and stores in variable number.
Finally, the value stored in the variable number is displayed on the screen using printf()function.

Comments

Popular

C Program to Display Prime Numbers Between Two Intervals #33

C if...else Statement

C switch...case Statement

C Program to Convert Binary Number to Decimal and vice-versa #39

C Programming Structure and Pointer

C program to Reverse a Sentence Using Recursion #43

Keywords and Identifiers