Skip to main content

power function to calculate pow(x,y)

#include<stdio.h>

/* Program:- power function to calculate pow(x,y)
 * Author:-  Surendra Patil
 * Date:-    10th July 2013
*/

/* power func prototype */
int power(int,int);

int main ()
{
        int m,n;
        printf("Enter the value of n and m \n");
        scanf("%d %d",&m,&n);
        printf (" power = %d\n",power(m,n));
        return 0;
}

int power(int base,int n)
{
        int i,result = 1;
        for (i=1;i <=n;i++)
                result *= base;
        return result;
}

Input:-

Enter the value of n and m
3  4

Output:-

Power = 81




Comments