0
How is the variable ( double and single) is used in c++
5 ответов
+ 4
"a double has 15 decimal digits of precision, while float has 7 and a long double has about 21 decimal digits of precision."
Wonderful!
#include <iostream>
#include <limits>
using namespace std;
int main() {
cout << numeric_limits<float>::max_digits10 << endl; // 9
cout << numeric_limits<double>::max_digits10 << endl; // 17
cout << numeric_limits<long double>::max_digits10 << endl; // 17 on VS - 21 on GCC
}
+ 3
Do you mean
// definition
int a = 0;
// first usage
a = 8 * 2;
// printing
cout << a << endl; // 16
// second usage
++a;
// printing
cout << a << endl; // 17
~~~~~~~~~~
Or do you mean the usage of `double` and `float` (single-precision) variables like so
double d = 4.5;
float f = 4.5f;
Your question is so obscure!
+ 2
Since the value of the flag `b` never gets altered, it's absolutely unnecessary to put the output statement into such block. But, for example, if the code was this way
int x = 5;
while (x--) {
if (!(b)) {
cout << a;
}
b = !b;
}
Output:
10.6286
10.6286
10.6286
Then it could've made a difference. It prints 3 out of 5.
+ 1
a double has 15 decimal digits of precision, while float has 7 and a long double has about 21 decimal digits of precision.
There is no data type called single in C++.
0
#include <iostream>
using namespace std;
int main() {
double a = 10.6286;
bool b = false;
if (!(b)){
cout << a;
}
return 0;
}
Output :
10.6286
Here, this (!) is sign of not, which reverse any result, if it is true it will reverse to false or if result is false it will reverse to true.
That's what I did here.
if(!(b)){
cout << a;
}
Here, value of b is false and the not sign will make it true so it will print the value of a.