lucproblem012.c
Problem Statement
lucproblem012.c
Write a Function power(a, b), to calculate the value of a raised to b
Source Code
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
● Author - Amit Dutta · Updated - 12 Dec 2025