I have written a code. I am getting an wrong or unexpected answer form the code. The value of 2nd index of the array named arr should be 800 but it is showing 799. Other values are right.
Here is my C++ code:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int n = 9876, count = 0, temp, size = (int) to_string(n).length();
vector<int> arr;
for (int i = 0; i < size; i++) {
temp = (n % 10) * pow(10, i);
arr.push_back(temp);
n /= 10;
cout << arr[i] << " ";
}
return 0;
}
The output of the program is:
6 70 799 9000
Here the third number is 799
but I think it should be 800
Why I'm getting this wrong answer?