1 year ago

#380709

test-img

Mayank Tyagi

Unexpected output when converting double data type to integer data type

I am writing a program where I want to know a number can be written in the form of x^y.

I know that log(base, a) = log2(a)/log2(base);

input => 823543
output => 7^7

So if I am doing:

double res = log(823543)/log(7);
int intRes = (int) res;
cout << res << ", "<<intRes << endl;

I'm getting

>>> 7, 6

Why does 7 become 6 when assigning to int from double?

c++

integer

double

0 Answers

Your Answer

Accepted video resources