W.a.p. in c language to calculate power of any number without using string library function.
Hello,
Since you've mentioned "without using recursion" I've written the following code using recursion.
#include <stdio.h>
long power (int num, int pow)
{
if (pow)
{
return (num * power(num, pow - 1));
}
return 1;
}
int main()
{
int pow, num;
long result;
printf("Enter a number: ");
scanf("%d", &num);
printf("Enter it's power: ");
scanf("%d", &pow);
result = power(num, pow);
printf("%d^%d is %ld", num, pow, result);
return 0;
}