#include <stdio.h>
/* C program to Input integer, float and character values using scanf(). */
int main()
{
int inputInt;
char inputChar;
float inputFloat;
/* Take input from user using scanf function */
printf("Enter Integer,Character and Float number\n");
scanf("%d %c %f", &inputInt, &inputChar,
&inputFloat);
printf("\nInteger you have entered is : %d", inputInt);
printf("\nCharacter you have entered is : %c", inputChar);
printf("\nFloating point number you have entered is : %f",
inputFloat);
return 0;
}
Output:
Enter Integer,Character and Float number
15
C
2.500
Integer you have entered is : 15
Character you have entered is : C
Floating point number you have entered is : 2.500000
Explanation:
1.
int inputInt;
char inputChar;
float inputFloat;
Variable inputInt is declared as int to store integer value.
The inputChar is declared as char variable for to store any character value.
and inputFloat is declared as float to store floating(decimal point ) values.
2. printf("Enter Integer,Character and Float number\n");
scanf("%d %c %f", &inputInt, &inputChar,
&inputFloat);
Shows the message on console
"Enter Integer,Character and Float number"
The values entered by user is
15
C
2.500
the scanf("%d %c %f", &inputInt, &inputChar,
&inputFloat);
function store the entered values 15 in the variable inputInt, 'C' is stored in inputChar and 2.500 is stored in inputFloat respectively.
3. printf("\nInteger you have entered is : %d", inputInt);
printf("\nCharacter you have entered is : %c", inputChar);
printf("\nFloating point number you have entered is : %f",
inputFloat);
above 3 printf() functions displays the output.
Integer you have entered is :15
Character you have entered is : C
Floating point number you have entered is :2.500000