Find the power of a number using for loop with C.
#include <stdio.h>
int main()
{
int base, exp;
long long power = 1;
int i;
printf("Enter base: ");
scanf("%d", &base);
printf("Enter exp: ");
scanf("%d", &exp);
for (i = 1; i <= exp; i++)
{
power = power * base;
}
printf("%d ^ %d = %lld", base, exp, power);
return 0;
}
Output:-
Enter base : 2
Enter exp : 5
2 ^ 5 = 32
0 Comments