Formatting Numbers in Program Output :

The printf function in C provides powerful capabilities for controlling the
appearance of output data. Numeric values can be formatted to specify the number
of digits displayed, the number of digits after the decimal point, and the total
field width.

Formatting is achieved using format specifiers embedded within the format
string passed to printf. These format specifiers inform the function how to
interpret and display the corresponding data values. Proper formatting improves
program output readability and ensures that numeric data is displayed in a clear
and consistent manner.
%d for integers
%f  for floats
%l  for long
%c for character
SYNTAX:

printf("format_string", variable_list);
EXAMPLE:

#include <stdio.h>

int main() {
    char a ='h';
    char aa[] = "hello";
    int b=1;
    float c = 73.6757;
    printf("%.2f",c);

    return 0;
}

Output:

73.68
Previous Next