codescracker
c

C Program to Print Integer



« Previous Program Next Program »

In this article, you will learn that how to print an integer value on output screen in C programming. Here printing of an integer is implemented in two programs:

Print an Integer

To print integer value in c programming, use printf() function with %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 build and run under Code::Blocks IDE. Here is its sample output:

c program print integer

The variable num is declared (of int type) and initialized with 10. Print its value using %d format specifier.

Print an Integer entered by User

This program receives an integer value from user at run-time and print the same on 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:

c print integer entered by user

Now enter any numerical value say 20 and press ENTER key to see the following output:

print integer value in c

Same Program in Other Languages

C Online Test


« Previous Program Next Program »



© Copyright 2021. All Rights Reserved.

CodesCracker