Originally Posted by
jedi_jinn
Code:
#include <stdio.h>
#include <math.h>
int main()
{
int base, exp;
scanf("%d", &base) ;
scanf("%d", &exp) ;
printf("%d ^ %d = %d\n", base, exp, pow(base,exp)) ;
return 0;
}
The above code prints the output of pow as a 0. What did I do wrong? I tried %f also, but that gave me a number with alot of zeroes after the decimal. How can I get a normal integer without casting pow? Thank you.
Code:
printf("%i ^ %i = %i\n" , base, exp, pow(base, exp));
Try that.
Or, you can always error check.
Code:
int main()
{
int base, exp, powr;
scanf("%d", &base) ;
scanf("%d", &exp) ;
powr = pow(base, exp);
if(powr != 0)
{
printf("%i ^ %i = %i\n", base, exp, powr) ;
}
else
{
printf("Error calculating pow()");
return 0;
}