Print an integer in C – from user input

Example to print an integer in C programming from user input. User will be prompted to enter an integer number on console screen. The program will read the integer number entered by user and display on screen.

Steps:

  • Create an integer variable
  • Prompt user to enter an integer number using printf function
  • Read the entered number using scanf function
  • Display the number on screen using printf function

C program to print an integer entered by a user

/*---------------------------------------------------
* Example to print an integer in C entered by user
* 
*/

int main(){

	//Create an integer variable to store entered
	//number
	int number;

	//Prompt user to enter an integer number
	printf("Enter an integer:\n");

	//Read the entered integer number using scanf from
	//
	scanf("%d", &number);

	//Display the integer on console.
	printf("You entered an integer number: %d\n", number);


	return 0;
}

Output:


Enter an integer:
12
You entered an integer number: 12

Related Posts