C Program to Print an Integer - Read & Display User Input

Print an Integer Entered by the User

This example reads an integer from the user and prints it back to the console.

#include <stdio.h>
int main() {
    int number;
    printf("Enter an integer: ");
    scanf("%d", &number);
    printf("You entered: %d\n", number);
    return 0;
}
Enter an integer: 25
You entered: 25
        

The program declares an int variable, prompts the user and reads a value into it. The printf() call then prints the value in a formatted string. Using scanf() ensures that the user’s input is stored in the variable before printing.


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...