Thursday, March 15, 2012

Exponentiation

Function integerPower( base, exponent ) returns the value of baseexponent
/*
   title: exponentiation
   author: aeriqusyairi
   date: Jan23 2012
*/

#include<stdio.h>

double integerPower(int, int);

int main(){
    int a = 0, b = 0;
    double c = 0;
    
    printf("Input base and exponent...\nBase:");
    scanf("%d", &a);
    printf("Exponent:");
    scanf("%d", &b);
    
    c = integerPower(a, b);
    
    printf("The value of %d to the power of %d is %.2lf\n", a, b, c);
    
    system("pause");
    return 0;
}

double integerPower(int base, int exponent){
   int i;
   double result = 1;
   for(i = 1; i <= exponent; i++)
      result*= base;
   return result;       
}

No comments:

Post a Comment