Simple Calculation
Format
Type | Specifier | intput/output as |
---|---|---|
char | %c | character |
int,short | %d | decimal integer |
float | %f | floating-point |
double | %lf | floating-point |
- The default number of decimal places displayed by
%f
and%lf
is 6. To display two decimal places, we write%.2f
or%.2lf
.
Simple input
The scanf(...)
command takes in information from the user and keeps it in a special place in the computer's memory linked to a certain variable in the program.
scanf(format, address);
- address: contains the address of the destination variable. use the prefix
&
to refer to the 'address of' of a variable.
Simple output
The printf(...)
command shows the user the value of a certain variable or result of an operation.
printf(format, expression);