0

why this output 0 ? #include <iostream> using namespace std; int main() { double x=(7%6)/2*5; cout<<x; }

30th Aug 2016, 5:15 PM
Lekhraj Singh
Lekhraj Singh - avatar
3 Respostas
+ 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;
30th Aug 2016, 6:03 PM
Zen
Zen - avatar
+ 2
here' / 'does not represent normal division. It represents quotient after performing division. 1/2=0
30th Aug 2016, 5:41 PM
B Manoj Kumar
B Manoj Kumar - avatar
+ 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.
31st Aug 2016, 6:31 AM
Turgai Shikhlinski
Turgai Shikhlinski - avatar