Program for Print Integer in C

How to Print Integer in C programming?

It is very important for a program to display some output as to show that the program compiled successfully or not, but before doing that lets learn to Print integer in C on the stdout console. This is generally done by using the “printf” command in C programming language.

Print-integer-in-c

Syntax:

A general code to Print Integer in C language.
printf("%d", variableOfIntegerType);
  • printf– it is the predefined function to display something on the stdout console
  • %d– it is the datatype of the variable that is to be displayed.
  • variableOfIntegerType– it is the name of the variable that store value that is to be displayed by the printf function.

General Steps to Print Integer in C:

  • Step 1: Start
  • Step 2: Declare the variable num.
  • Step 3: Read input num from the user or can even initialize on your own. 
  • Step 4:While reading the input from the user use scanf() command to store the value in num.
  • Step5: To print the value stored in num use printf() command.
  • Step 6: As per the syntax use the datatype in-place of any and variable name instead of variableOfAnyType.
  • Step 7: The above step would print the value stored in num.
  • Step 8: Program end.

Working:

In these program we will learn to print integer by various methods.

Example 1 :

A simple program where we will Print Integer in C where variable value is pre-defined.

Run
#include<stdio.h>
int main()
{
    int num=24;
    printf("Entered integer is: %d", num);
    return 0;
}

Output:

Entered integer is: 24

Example 2 :

Program where we willPrint the Integer in C where value of the variable is entered by the user.

Run
#include<stdio.h>
int main() {   
    int number;
    printf("Enter an integer: ");  
    // reads and stores input
    scanf("%d", &number);

    // displays output
    printf("You entered: %d", number);
    
    return 0;
}

Input:

Enter an integer: 564

Output:

You entered: 564

Example 3 :

Program where we will count the number of digit using a function.

Run
#include<stdio.h>
int main()  
{  
    int num;
   printf("Enter an integer: ");  
    
    // reads and stores input
    scanf("%d", &num);

    // displays output by the function
    printingfun(num);
    
    return 0;
}  
void printingfun(int num)  
{  
     printf("You have entered the intereger %d",num);
}  

Input:

Enter an integer: 587

Output:

You have entered the intereger 587

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription