A program that accepts two positive integer values x and n, and uses a function to calculate the value of x raised to the power n. The function should calculate power by repeated multiplications. The result should be returned to the main function and displayed.
I use linux terminal to run this program.There is no error but its returning me "Answer =0 "
Whats wrong with these lines of codes?
int power(a,b)
{
do
{
a=a*a;
b=b-1;
}
while (b>=1);
return 0;
}
int main()
{
int x,n;
int ans;
printf("Enter the value of x: ");
scanf("%d",&x);
printf("Enter the value of n: ");
scanf("%d", &n);
ans = power(x,n);
printf("Answer = %d \n", ans);
}