BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Print an Integer entered by the user

Last Updated: July 22, 2022 by Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how to write a C program to print an integer entered by user. This is a very simple program. You just need to capture the user input using scanf, and store it in an int variable, then you can use printf to print the value of the variable.

C Program to print an integer

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

  printf("Enter an integer: ");

  // reads the user input stores in 'number'
  scanf("%d", &number);

  // print the 'number'
  printf("Integer entered by user: %d", number);

  return 0;
}

Output:
C Program to Print an Integer entered by the user
Explanation of the above program:
This is how a variable is declared, since we want to store an integer number so we have declared the variable as int. The variable name can be anything, however it is good to choose a meaningful simple name:

int number;

This line displays a message to the user to enter a number:

printf("Enter an integer: ");

Entered number is scanned and stored in variable number:

scanf("%d", &number);

Finally the value of the variable number is displayed:

printf("Integer entered by user: %d", number);

Related C examples:

  • C Program to find the average of two numbers
  • C Program to find ASCII value of a character
  • C Program to check leap year
  • C Program to swap two numbers
❮ C TutorialC Programs ❯

Top Related Articles:

  1. C Program to concatenate two strings without using strcat
  2. C Program to Read the First Line From a File
  3. C Program to check Armstrong number
  4. C Program to read and print employee details using structure
  5. C Program to find the Size of int, float, double and char

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap