in , ,

C Program to Print an Integer (Entered by the User)

C Program to Print an Integer (Entered by the User)
C Program to Print an Integer (Entered by the User)

C Program to Print an Integer (Entered by the User)

In this example, the integer entered by the user is stored in a variable and printed on the screen.

To understand this example, you should have knowledge of the following C programming topics:

C Variables, Constants, and Literals

C Data Types

C Input-Output (I/O)


Program to Print an Integer

#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;
}

Output

Enter an integer: 25
You entered: 25

In this program, an integer variable number is declared.

int number;

Then, the user is asked to enter an integer number. This number is stored in the number variable.

printf(“Enter an integer: “);
scanf(“%d”, &number);

Finally, the value stored in the number is displayed on the screen using printf().

printf("You entered: %d", number);

Please feel free to give your comment if you face any difficulty here.

For more Articles click on the below link.

salman khan

Written by worldofitech

Leave a Reply

C "Hi, World!" Program

C “Hello, World!” Program

C Program to Add Two Integers 

C Program to Add Two Integers