0
How i can write power base code without using pow () function in c
I want to increase base value and similar power value too
2 Respuestas
+ 2
Multiply number , the power times. Use a loop to do it.
double value = 1;
From 1 to n times, repeat
value = value * num;
+ 1
//complete answer about this code at https://code.sololearn.com/c24WohfoM7aB/?ref=app
#include <stdio.h>
double power(double num,int p) {
double ret=num;
if(!p)return 1;
if(p<0){ret=num=1/num;p=-p;}
while(--p) ret*=num;
return ret;
}
int main()
{
int num,p;
printf("Enter number & power:\n");
scanf("%d %d",&num,&p);
printf("pow(%d,%d) = %.15f", num, p, power(num,p));
}