Learn about C Program to Find Power of a Number using while loop in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C Program to Find Power of a Number using while loop
The below program takes base and the exponent value as input and calculates the power of the value and displays the final result.
Source code:
#include<stdio.h>
int main()
{
int base, exponent;
long power=1;
printf("Enter base and Exponent: ");
scanf("%d %d",&base,&exponent);
while(exponent!=0)
{
power *= base;
exponent--;
}
printf("Result = %ld\n", power);
return 0;
}
Output:
Enter base and Exponent: 10 2
Result = 100
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Print Multiplication Table from 1 to N
C program to print multiplication table from 1 to 10