Hello Devs,
In this tutorial, we are going to learn C program to calculate power of a number.
Here is a well-commented example you can understand and analyze.
# include <stdio.h>
int main(){
int pow,num,i=1;
long int sum=1;
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\nEnter power: ");
scanf("%d",&pow);
while(i<=pow){
sum=sum*num;
i++;
}
printf("\n%d to the power %d is: %ld",num,pow,sum);
return 0;
}
I hope this example helps you.