Printing An Integer in C

Write a C program that prints an integer entered by the user.

Click here to view the solution!
#include <stdio.h>

int main() {   
     int number; // int number declares the integer variable (numnber)
    
     printf("Type in your integer: ");  
  
     scanf("%d", &number); // scanf() function reads and stores input
  
     printf("here is your integer: %d", number);   // Printf() function displays output
  
     return 0;
} 

Click Here to View the Output!

Type in your integer: 30

Here is your integer: 30

Click Here to View the Explanation!
  • For this program, we start by declaring an integer variable number.  We then use the printf("Enter an integer: "); to request the user for an integer and save it to our (number) using scanf("%d", &number).
  • Finally, we use the printf() function to display the value we stored in our integer variable number

%d bloggers like this: