Take input from console in C by R4R Team

-We use scanf() function to take a input from the user in console.

Syntax-
scanf("format specifier",&variable);

- Here format specifier is the type of the variable like %d,%f,%c etc.
- '&' is used in scanf(), without '&' it will give an error.
- variable is the object where we want to store our value.


program-

#include< stdio.h>
int main()
{
int a;
float b;
char c;
printf("Enter integer valuen");
scanf("%d",&a);
printf("Enter float valuen");
scanf("%f",&b);
printf("Enter any character n");
scanf("%s",&c);
printf("Your integer number is %d",a);
printf("Your float number is %f",b);
printf("Your character is %c",c);
}


output-

Enter integer value
15
Enter float value
1.234
Enter any character
a
Your integer number is 15
Your float number is 1.234000
Your character is a




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!