How i can write power base code without using pow () function in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

26th Aug 2022, 4:57 PM
Aadesh Walhe
Aadesh Walhe - avatar
2 Answers
+ 2
Multiply number , the power times. Use a loop to do it. double value = 1; From 1 to n times, repeat value = value * num;
26th Aug 2022, 5:07 PM
Jayakrishna 🇮🇳
+ 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)); }
26th Aug 2022, 7:58 PM
Ciro Pellegrino
Ciro Pellegrino - avatar