Two formatted input and output functions
These two functions are very frequently used in programming and provide a provision for inputting and outputting data or messages.
1. printf(): It is used to print the constant value, literal value or values contained in the variables on the screen. The general form of printf() is:
printf("<format conversion string specification>", <list of variables/constants>);
2. scanf(): it is used to scan values from the keyboard. Thus, makes a provision for supplying values of variables through the keyboard in the program. The general form of scanf() is:
scanf("<format conversion string specificaton>",&<list of variable addresses >);
For example:
void main()
{
int a,b,c,avg;
printf("Enter values for a, b and c:");
scanf("%d %d %d",&a,&b,&c);
avg=(a+b+c)/3;
printf("avg=%d",avg);
}
Note: While supplying values for continuous variables through keyboard at runtime, values typed on the screen must be separated by a blank, a tab or a new line (enter).