C program to print an integer
In this article, you will learn how to print an integer value on the output screen in C programming. Here, the printing of an integer is implemented in two programs:
Print an integer in C
To print an integer value in C programming, use the printf() function with the %d format specifier, as shown here in the following program. The %d format specifier is used to output numerical data.
#include<stdio.h> #include<conio.h> int main() { int num=10; printf("Integer Value = %d", num); getch(); return 0; }
This program was built and runs in the Code::Blocks IDE. Here is its sample output:
The variable num is declared (of the int type) and initialized with 10. Print its value using the %d format specifier.
Print an integer entered by the user
This program receives an integer value from the user at run-time and prints the same on the output.
#include<stdio.h> #include<conio.h> int main() { int val; printf("Enter the Value: "); scanf("%d", &val); printf("You entered %d", val); getch(); return 0; }
Here is its initial output:
Now enter any numerical value, say 20, and press the ENTER key to see the following output:
The same program in different languages
« Previous Program Next Program »
Liked this post? Share it!