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

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 ❯

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 *

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2023 BeginnersBook . Privacy Policy . Sitemap