Print an Integer in C

Exercise:

Write a C Program to print an integer that is entered by the user.

Click Here to View the Solution!
#include <stdio.h>
int main() {
    int number;
    printf("Enter an integer: ");

    // reads and stores input in variable number
    scanf("%d", &number);

    // displays output
    printf("Entered Number = %d", number);
    return 0;
}
Click Here to View the Output!
Enter an integer: 5
Entered Number = 5
Click Here to View the Explanation!
  • This program is used to print an input entered by the user on the screen.
  • An integer variable number is initialized.
  • The scanf() function will take input from the user using the parameters %d and &number. %d takes a digit input while the & refers to the variable which will hold the input.
  • The printf() method prints the variable number holding the user input on the screen.
  • Return 0 statement ends the program.
%d bloggers like this: