We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/* The Question Should Have Specified That We Need To Set Precision For The Values Of Float & Double, I just wrote the simpler code like everyone and It did not work on the other test questions, I tried the questions 4-5 Times until I realised My code was not printing decimal values after some 3 or 4 digits then I came to know that I do have to set a precision value which I ultimately had to and I didn't how to, Googled It, learned something new from this question, here's my solution. */
include
include
include
using namespace std;
int main() {
int x;
long y;
char a;
float z;
long double d;
cin >> x;
cin >> y;
cin >> a;
cin >> z;
cin >> d;
cout << x <<"\n";
cout << y <<"\n";
cout << a <<"\n";
cout << fixed << setprecision(3)<< z <<"\n";
cout << fixed << setprecision(9)<< d <<"\n";
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Basic Data Types
You are viewing a single comment's thread. Return to all comments →
/* The Question Should Have Specified That We Need To Set Precision For The Values Of Float & Double, I just wrote the simpler code like everyone and It did not work on the other test questions, I tried the questions 4-5 Times until I realised My code was not printing decimal values after some 3 or 4 digits then I came to know that I do have to set a precision value which I ultimately had to and I didn't how to, Googled It, learned something new from this question, here's my solution. */
include
include
include
using namespace std; int main() { int x; long y; char a; float z; long double d; cin >> x; cin >> y; cin >> a; cin >> z; cin >> d; cout << x <<"\n"; cout << y <<"\n"; cout << a <<"\n"; cout << fixed << setprecision(3)<< z <<"\n"; cout << fixed << setprecision(9)<< d <<"\n";
}