Issue
I am trying a problem. I need to print the ans in 6 decimal digits. For example if the ans is 64, I want to print 64.000000 I tried the following way. what I did wrong?
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long t;
    cin>>t;
    float n;
    while(t--)
    {
        cin>>n;
        float s=(n-2)*180.000000;
        float w=(s/n)*1.000000;
        cout<<w*1.000000<<setprecision(6)<<endl;
    }
    return 0;
}
                        
                        Solution
You can make use of std::fixed:
#include <iostream> 
#include <iomanip>
void MyPrint(int i)
{
    double d = static_cast<double>(i);
    std::cout << std::setprecision(6) << std::fixed << d << std::endl;
}
int main() {
    MyPrint(64);
    MyPrint(100);
    return 0;
}
Running the above code online results in the following output:
64.000000
100.000000
                        
                        Answered By - BlueTune Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.