Why past 10^16 then you attempt minus 1 answer is 10^6 in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why past 10^16 then you attempt minus 1 answer is 10^6 in C++

So i need get answer for this 10^16-1 but then I do it it always end up being 10^16. with -2 and more it works perfect.. Is it rounds up by default then big number needs only 1 to change into ^17??? Maybe sb had similiar problem and knows how to bypass it

16th Feb 2018, 11:53 AM
Witalij Janukiewicz
Witalij Janukiewicz - avatar
5 Answers
+ 4
Subtracting small numbers from large numbers loses significant precision.
16th Feb 2018, 12:37 PM
John Wells
John Wells - avatar
+ 3
What data type are you using to store it?
16th Feb 2018, 12:33 PM
John Wells
John Wells - avatar
0
double because I need find sum of all numbers which has n digits 0<n<=100 I use arithmetic progression for that a1 = pow (10, n-1) an = pow ((10, n)-1)
16th Feb 2018, 12:33 PM
Witalij Janukiewicz
Witalij Janukiewicz - avatar
0
I see, maybe you have idea how to save that precision? or manipulate to get number 10^n - 1 in other way
16th Feb 2018, 12:40 PM
Witalij Janukiewicz
Witalij Janukiewicz - avatar
0
also I don't understand why then I minus 2 it works well
16th Feb 2018, 12:46 PM
Witalij Janukiewicz
Witalij Janukiewicz - avatar