In this program scenario, we will see how to take an integer as input from user and print an integer value to console screen.
An integer data can be considered as any whole number. Integer values are present with no fractional or floating point values.
Here understand that user will provide this integer data and then we have to echo/print this value on screen.
First take user input and store it inside variable called
Read the input into
IntNumusing scanf()function and specify %dformat specifier so compiler interprets it as integer data
Print the value on screen using
int IntNum; // declare the integer type variable IntNum
printf("\n Provide the integer:");
scanf("%d",&IntNum); // Read the value into IntNum
printf("\n Input Integer = %d",IntNum); //print the value to screen
Provide the integer:23
Input Integer = 23
In this program, we have declared a variable called
Next we are displaying a message to the user that tells the user to provide the input.
Again we have used
We just need to specify variable name after message in double quotes and put it separated by a comma. In the end return 0 statement is added because the main method has return type int and we must return a value to function so that return 0 is added. It indicates status as the successful execution of the program.