write a program to input two integers x and n, compute x^n using a loop
Answers
Answered by
7
Answer:
Explanation:
Power of a Number Using the while Loop
#include <stdio.h>
int main() {
int base, exp;
long long result = 1;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exp);
while (exp != 0) {
result *= base;
--exp;
}
printf("Answer = %lld", result);
return 0;
}
Output
Enter a base number: 3
Enter an exponent: 4
Answer = 81
Similar questions