0
What is answer of this
a=13 b=7 a/=b cout<<b-a
6 Réponses
+ 1
It depends on the a and b variables' data types.
For double and float it is 5.14286.
For int is is 6.
http://code.sololearn.com/c0jpgaSEC1K8/
// Double (and float) keep decimal fractions
double doubleA = 13;
double doubleB = 7;
doubleA /= doubleB; // A/B = 13/7 = 1.85714. A = 1.85714
cout << "Double: " << doubleB - doubleA << endl; // B-A = 7-1.85714 = 5.14286
// Int truncates decimal fractions
int intA = 13;
int intB = 7;
intA /= intB; // A/B = 13/7 = 1.85714, but is truncated down to 1, so now A = 1
cout << "Int: " << intB - intA << endl; // B-A = 7-1 = 6
0
6
0
a=a/b; //13/7=1.system don't take in. float.so,now a=1
b-a=7-1=6
0
a=a/b; //13/7=1.system don't take in. float.so,now a=1
b-a=7-1=6
- 1
6
- 1
if in float it is =7-1.7=6.3
and if it is int then =7-1=6