Menu

Add Topic

Forum

waiting answer January 05, 2021

Write a program to print an Integer in C?

Answers
January 05, 2021

Required knowledge: C Input/Output, C Variables,  C Datatypes

In this example, a variable num is declared. The input number num is stored in the variable num and displayed on the screen using printf(). To store the entered value in a variable, we use the scanf() in c programming.

Program Description: print an Integer in C

    #include 
    int main() {   
        int num;
       
        printf("Enter an integer number: ");  
        scanf("%d", &num);
        printf("The entered is %d", num);
        
        return 0;
    }

OUTPUT

        Enter an integer number: 5
        The entered is 5

0 0
January 05, 2021

  • The printf function is used for displaying the output on the screen.
  • The scanf() function is used to store/reads the entered value in a variable.

PROGRAM

    #include <stdio.h>
    int main()
    {
       int innum;
       printf("Enter an integer number: ");
       scanf("%d", &innum);
       printf("The number entered is: %d", innum);
       return 0;
    }

OUTPUT

         Enter an integer number: 5
         The number entered is: 5

0 0
January 05, 2021

Required knowledge: C Variables, C Input/Output, and C datatypes

    #include <stdio.h>
    int main()
    {
        int number; // Declaring integer variable 'number'. This variable hold value of number entered by user
        printf("Input an integer number:"); // Displaying message to user which is in double quotes 
        scanf("%d", &number); // Read integer number using "%d"
        printf("The Entered number is %d", number); // Displaying 'num' on screen
        return 0;
    }

OUTPUT

    Input an integer number:10
    The Entered number is 10

0 0

Please Login to Post the answer

Leave an Answer