Dec 15, 2011

Program: Using setprecision() Function

Program: Using setprecision() Function


Setprecision function is used to set a number of places upto digit shown on screen like i wanna to display upto 10 digit palace so i write 10 in setprecision it set the maximum range of decimal place 10 no float value can exceed this decimal place means maximum term after the decimal is 10 & it can used using iomanip header file. 





Check out Working of Setprecision
#include<iostream.h>
#include<conio.h>
#include<math.h>  //for sqrt function
#include<iomanip.h> // for setprecision function
int main()
{
float a,b; /* we can define more than one variable with same datatype you have to put comma(,) with every variable & you can also initialize value to that variable like int a = 0; */
cout << "Enter Any Number\n";
cin >> a; // take value from user
b = sqrt(a); // b variable store value of square root of a variable


cout << "Square Root = " << setprecision(6) << b; 
/* setprecision() is used to set number of places to be shown like i wanna find square root of 42 it shows 6.48074 total number is 6 as we set setprecision(6) if we set 10 it show 6.480740547 here total number is 10. SO you can set as your requirement

*/


getch();
return 0;
}




OUTPUT





0 comments:

Post a Comment