Skip to content
Home » C program to find a^b

C program to find a^b

Below is the code to find power of a number

#include <stdio.h>
int main(){
int a,b,res=1;
printf("Enter base:");
scanf("%d",&a);
printf("Enter power:");
scanf("%d",&b);
if(b==0){
printf("%d^%d is 1",a,b);
}else{
for(int i=1;i<=b;i++){
res*=a;
}
printf("%d^%d is %d",a,b,res);
}

}

Output:

Enter base:5
Enter power:2
5^2 is 25