power of a given number
C programming Tutorials

C Program to Calculate the Power of a Number

C Program to Calculate the Power of a Number

  • C Program to calculate the power of a number is generally asked in university exam.
  • We can implement this program in c using predefined pow ( ) function and can also implement without using pow( ) function.
  • Here in this tutorial we have implemented power calculation power without using pow( ) function.
  • The program below takes two integers from the user first is a base number and second is  an exponent and calculates the power.

Algorithm to Calculate the Power of Given Number

Algorithm to calculate the power of a given number is given below

Step 1: Declare int type variable number and long int  type variable power.

Step 2: Enter the value of number for which we have to find power.

Step 3: Enter exponent or power value through console.

Step 4: Execute the While loop until powervalue !=0 and repeat the following steps

power = power*number;

powervalue — ;

Step 5: Print the result.

C Program to calculate the power of a number without using pow()function is given below-

#include<stdio.h>

#include<conio.h>

void main( )
{

int number, powervalue;

long power=1;

printf(“Enter number and powervalue: “);

scanf(“%d %d”,&numbere,&powervalue);

while(powervalue! = 0)
{

power = power*number; //power= power * base

powervalue =powervalue -1 ;
}
printf(“Result = %ld\n”, power);
}

Output

power of a given number

Leave a Reply

Your email address will not be published. Required fields are marked *