I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h> //function declaration double Power(double base, int exponent); int main() { double base, power; int exponent; // Inputting base and exponent from user printf("Enter base: "); scanf("%lf", &base); printf("Enter exponent: "); scanf("%d", &exponent); // Call Power function power = Power(base, exponent); printf("%.2lf ^ %d = %f", base, exponent, power); return 0; } /* Calculating power of any number. Returns base ^ exponent */ double Power(double base, int exponent) { // Base condition if(exponent == 0) return 1; else if(exponent > 0) return base * pow(base, exponent - 1); else return 1 / pow(base, - exponent); }
Result:
Enter base: 5
Enter exponent: 3
5.00 ^ 3 = 125.000000
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter base: 5
Enter exponent: 3
5.00 ^ 3 = 125.000000
need an explanation for this answer? contact us directly to get an explanation for this answer