Write a c program to calculate the power of a number
Answers
Answered by
1
Answer:
The program below takes two integers from the user (a base number and an exponent) and calculates the power.
For example: In case of 23
2 is the base number
3 is the exponent
And, the power is equal to 2*2*2
Example #1: Power of a Number Using while Loop
#include <stdio.h>
int main()
{
int base, exponent;
long long result = 1;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exponent);
while (exponent != 0)
{
result *= base;
--exponent;
}
printf("Answer = %lld", result);
return 0;
}
Output
Enter a base number: 3
Enter an exponent: 4
Answer = 81
Similar questions