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

by | Dec 30, 2022 | C, C Programs

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

Introduction

In this program, we will print the value of the integer on the screen that is entered by the user. Although the code for this particular program will be very easy. We all should be aware of some concepts. Those topics are:

  • Declaration of a variable,
  • Format specifiers,
  • Addresses.

Program

#include<stdio.h>
int main()
{
int a; // declaration of variable ‘a’
printf("Enter the value of integer:\n");
scanf("%d",&a);
printf("Value of integer is %d",a);
return 0;
}

 

Output

Explanation

A variable ‘a’ of ‘int’ data type is declared because there is a need of an integer type variable which will store the integer value entered by the user.

A message is printed (with the use of ‘printf’ function) on the screen asking user to enter an integer type value.

scanf(“%d”,&a); , ‘scanf’ function is used to take input from the user. Since the value entered by user is of ‘int’ data type thus %d format specifier is used.

The value entered by user will get stored at the address of a.

printf(“Value of integer is %d”,a); ,this statement gets printed as it is along with the value of ‘a’ at the place of %d.

So, successfully we have stored the value input by the user at the address of ‘a’. Thus, the value entered by the user will be stored in the variable ‘a’.

 

Author

0 Comments

Submit a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author