Skip to content
Home » C program to find x power y using for loop

C program to find x power y using for loop

Learn about C program to find x power y using for loop in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to find x power y using for loop

The Below C program finds the power of the given number. The base and exponent values are given by the user and the result is calculated using for loop.

Program:

 #include<stdio.h>
 int main()
 {
     int base, exponent, i;
     long power=1;

     printf("Enter base and Exponent: ");
     scanf("%d %d", &base, &exponent);

     for(i=1;i<=exponent;i++)
     {
         power *= base;
     }

     printf("Result = %ld\n",power);

     return 0;
 }

Output:

Enter base and Exponent: 5 2
Result = 25

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program to Find Power of a Number using while loop
Print Multiplication Table from 1 to N