SETTING PRECISION

How I can print answers to a precision of 2 digits to values such as:-
29.0
32.000
.
.
.
etc.

In C:

printf("%.2f", val);

where val is a float/double variable you want to print to a precision of 2 decimal places.

In C++, its like this:

cout.precision(2);

std::ios_base::fmtflags old = cout.setf(std::ios_base::fixed, std::ios_base_floatfield);

You can restore to the previous mode by doing this:

cout.setf(old, std::ios_base_floatfield);

in C/C++ :

double d = 3.14159265358979;
cout.precision(3);
cout << "Pi: " << fixed << d

In C++ (using iostream) :

double d = 3.14159265358979; 
printf("%.3f",d);