C Program to Calculate the Power of a Number using for loop

Posted on

C Program to Calculate the Power of a Number using for loop

  • Input base and exponents from the user. Store it in two variables say base and expo.
  • Declare and initialize another variable to store power say power = 1.
  • Run a loop from 1 to expo, increment loop counter by 1 in each iteration. The loop structure must look similar to for(i=1; i<=expo; i++).
  • For each iteration inside loop multiply power with num i.e. power = power * num.
    Finally after loop you are left with power in power variable.