lucproblem012.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 12 Dec 2025
- License — MIT
Problem Statement ​
Problem Statement
Write a Function power(a, b), to calculate the value of a raised to b
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
double power(double, int);
double power(double a, int b)
{
if (b == 0)
return 1;
double res = 1;
int i;
if (b > 0)
for (i = 1; i <= b; i++)
res *= a;
return res;
}
int main()
{
double a, result;
int b;
printf("Enter the value and the power (Format A^B) : ");
scanf("%lf^%d", &a, &b);
result = power(a, b);
printf("Result of %g^%d = %g", a, b, result);
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26