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

Printing Integer values in C :

* This entered value is now stored in the variableOfIntType.
* Now to print this value, the printf() method is used. The printf() method, in C, prints the value passed as the parameter to it, on the console screen.

Syntax :
printf("%d", variableOfIntType);​
Program :
// Integer value
#include 

int main()
{
	// Declaring integer
	int x = 5;

	// Printing values
	printf("Printing Integer value %d", x);
	return 0;
}
Output :
Printing Integer value 5

Reading Integer values in C :

* The user enters an integer value when asked.

* This value is taken from the user with the help of the scanf() method. The scanf() method, in C, reads the value from the console as per the type specified.

* For an integer value, the X is replaced with the type int. The syntax of the scanf() method becomes as follows then:

Syntax :

scanf("%d", &variableOfIntType);​
Program :
// C program to take an integer
// as input and print it
#include 

int main()
{
	// Declare the variables
	int num;

	// Input the integer
	printf("Enter the integer: ");
	scanf("%d", &num);

	// Display the integer
	printf("Entered integer is: %d", num);

	return 0;
}
Output :
Enter the integer : 10
Entered integer is : 10