Here is a sample of source code
#include <iostream.h>
#include <conio.h>
#include <math.h>
int main()
{
int i=2,a;
a= pow(10,i);
int b=0;
b+=a;
cout<<b;
getch();
}
The ouput I expect is 100 as it is clear. But the compiler give 99 as output. Can anyone please explain what is the problem in the code and how it can b corrected to get 100 as output.
Change this line:
You can write the
roundfunction as:NOTE:
pow()returns a double, so the best way to avoid such problem is to makeadouble, notint.