- On
- By
- 0 Comment
- Categories: Basic, Basic C language
Write a C program to print an integer
Write a C program to print an integer
In this tutorial, we will discuss a simple concept of Write a C program to print an integer – entered by user
In this post, we are going to learn about how to print a integer number entered by user in C programming language
The value is stored in a variable num using scanf() function and it is displayed on the screen usint printf() function
Program 1
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int num; //variable declaration printf("Enter an integer: \n"); //printf() displays the formatted output scanf("%d",&num); //scanf() reads the formatted input printf("you entered %d",num); getch(); return 0; }
When the above code is executed, it produces the following results
Enter an integer 56 you entered 56
In the C program, the user can enter a value using scanf() function and the value stored in a variable named as num. then, the value prints using printf() function.
In this program, printf() function provides a piece of information to the user to entering an integer value
printf("Enter an integer: \n");
The scanf() function reads an integer data from the user and stores in variable num
scanf("%d",&num);
Finally, the value stored in the variable num is displayed on the screen by using printf() function
printf("you entered %d",num);
Recommended post
Write a C program to print an integer
Write a Cpp program to print an integer
Write a Python program to print an integer
write a Java program print characters of a string
write a C++ code to print characters of a string
write a C Code to print characters of a string
write a Java program to print characters of a string
Suggested for you