When I execute this code the value of ans1, ans2 is 50002896 and 50005000.
I know there is some issues with ceil function but was not able to figure out the exact cause.
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long ans1 = 0, ans2 = 0;
for (long long i = 1; i <= 10000; i++)
{
ans1 = ans1 + ceil((float)i / 1);
ans2 = ans2 + i;
}
cout << ans1 << " " << ans2 << endl;
}
#include <bits/stdc++.h>-- Include the proper header files, not this one.using namespace std;without knowing what that non-standard header file is pulling, in, we don't know if it isstd::ceilorceilfrom the C runtime library. That's why usingbits...whateveris a bad idea, let alone it isn't standard.std::ceilandceil#include <bits/stdc++.h>?, Why isusing namespace std;considered bad practice?