Dhruv Sb Dhruv Sb - 3 months ago 21
C++ Question

Power function is not working in c++

int n;
n = 2;
int d;
d = pow(10,n);
cout<<d<<endl;


It displays 99 instead of 100.
I have indcluded math.h

Answer

Try using this code printf ("%f\n", d);. printf is come from stdio.h and is faster than cout. Also, change the type of d from int to double because pow return double

Comments