Monday, 6 January 2014

A FUNCTION TO TAKE POWER OF GIVEN NUMBER (BASE AND EXPONENT WILL BE ENTERED BY THE USER).....!!!!!

#include<stdio.h>
int power(int *,int *);
int main()
{
    int base=0,expo=0,pow=0;
    printf("Enter the base number:");
    scanf("%d",&base);
    printf("Enter the exponent:");
    scanf("%d",&expo);
    pow=power(&base,&expo);
    printf("Power of given base is %d",pow);
    getch();
    return 0;
}

int power(int *base,int *expo)
{
    int x,size;
    size=*base;
    for(x=1;x<*expo;x++)
    {
      *base=*base * size;
    }
    return *base;
}

No comments:

Post a Comment