Loading...
C Program to Print an Integer

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

In this example, we learn how to print an integer(entered by the user) on the screen.

Remainder :

To understand this example, you must have the knowledge of the following C programming topics:


Program to Print an Integer

#include <stdio.h>

int main() {
  int num;
  printf("Enter a number : ");
  scanf("%d", &num);
  printf("Number is %d", num);
  return 0;
}

Output

Enter a number : 47
Number is 47

Working of the above program

  • An integer variable num is declared.
  • int num;
  • Then we asked the user to enter an integer.
  • printf("Enter a number : ");
  • Then we take the user input using scanf() function and store the entered value in num variable.
  • scanf("%d", &num);
  • Finally, we print the value of num variable using %d format specifier in printf() function.
  • printf("Number is  %d", num);

- Related Topics