0
how to do (y = x^n) in C ?
for example y = 5^4 = 625
8 Respostas
+ 4
To calculate the power of two numbers, you can either implement a function yourself, or use the standard pow() function included in the <math.h> header file:
https://en.cppreference.com/w/c/numeric/math/pow
+ 1
Then you need to multiplicate x for itself n times. Like 5*5*5*5
Just uss a for loop
+ 1
Try this code
#include <stdio.h>
int main()
{
int base,power,i,result=1;
printf("enter base and power:");
scanf("%d %d",&base,&power);
for(i=1;i<=power;i++)
{
result=result*base;
}
printf("%dth power of %d is %d",power,base,result);
return 0;
}
0
need to do it withou pow
0
how it could look ?i cant imagine
0
Just try something.
If it works, congratulations.
If it doesn't work you have two possibilities:
1) try something else
2) post here your attept so that someone can tell you why it doesn't work
0
no ,i cant imagine how to write loop for
just write if you can loop for
0
Then that's what you need:
https://www.sololearn.com/learn/C/2927/