exponent program in c

Solutions on MaxInterview for exponent program in c by the best coders in the world

showing results for - "exponent program in c"
Claudio
30 Mar 2020
1#include <stdio.h>
2double mypow(double base, double power);
3int main()
4{
5
6  int base, exponent;
7  printf("Enter Base: ");
8  scanf("%d", &base);
9  printf("Enter Exponent: ");
10  scanf("%d", &exponent);
11  printf("%d to the power %d = %0.2lf\n", base, exponent, mypow(base, exponent));
12  return 0;
13}
14double mypow(double base, double power)
15{
16    double result = 1;
17    if (power >= 0)
18    {
19
20        while (power--)
21        {
22            result = result * base;
23        }
24
25        return result;
26    }
27    else if (power < 0)
28    {
29        while (power++)
30        {
31            result = result * base;
32        }
33        return 1 / result;
34    }
35}