calculating powers in c
#include <stdio.h>
int main(){
int base,power=1,exponent,expo;
double power2=1.0;
printf("Enter Base and exponent (3,2) : \n");
scanf("%d %d",&base,&exponent);
expo=exponent;
if(exponent > 0){
while(exponent != 0){
power*=base;
exponent--;
}
printf("%d to the power %d is %d",base,expo,power);
}else{
while(exponent != 0){
power2*=(1.0/base);
exponent++;
}
printf("%d to the power %d is %.10f",base,expo,power2);
}
return 0;
}