0
why this output 0 ? #include <iostream> using namespace std; int main() { double x=(7%6)/2*5; cout<<x; }
3 ответов
+ 4
When both operands are int, / is the euclidian division. Cast at least one operand as a double to prevent this.
double x = (double)(7%6)/2*5;
+ 2
here' / 'does not represent normal division.
It represents quotient after performing division.
1/2=0
+ 1
if you use the following the output is 2.5:
double x=(7%6)/2.0*5.0;
once you turn an operand into a fraction / is treated as float division.