C++ output type question

Q.  Predict the output:

float x= 3.1496;
cout << setpricision(2) << x;


- Published on 17 Jul 15

a. 3.14
b. 3.15
c. 3.00
d. None of these

ANSWER: None of these
 

    Discussion

  • Brijesh   -Posted on 24 Oct 15
    According to given question the answer will be 3.1 not 3.14 means you will get the answer up to one decimal place. If you want the answer up to 2 decimal place you have to write code as given below.
    void main()
    {
    float x= 3.1496;
    cout << fixed;
    cout << setprecision(2) << x;
    }
  • Brijesh   -Posted on 24 Oct 15
    void main()
    {
    float x= 3.1496;
    cout << fixed;
    cout << setprecision(2) << x;
    }

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)