C - Write program to control float number output width

Requirements

3.1415926535 to be displayed as 3.14

The value of p is displayed with 1 digit to the left of the decimal and 2 digits to the right.

0.00008 to be displayed as 0.0

Demo

#include <stdio.h>

int main()/*from w w w . j  a  va2 s  . c o  m*/
{
    printf("%1.2f\n",3.1415926535);
    printf("%1.1f\n",0.00008);
    return(0);
}

Result

Related Exercise