Long time no see
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
void power(double *x, int *exp, double *xpow, int *i);
|
||||
|
||||
int main(){
|
||||
double x, xpow;
|
||||
int exp, i;
|
||||
i = 1;
|
||||
|
||||
printf("Write: num pow\t(q for exit)\nWrite: ") ;
|
||||
|
||||
while (scanf(" %lf %d", &x, &exp) == 2){
|
||||
if ((x == 0) && (exp == 0)){
|
||||
printf("Result of 0 in pow 0 is undefind\n");
|
||||
}
|
||||
else if(exp == 0){xpow = 1;}
|
||||
else({
|
||||
xpow = x;
|
||||
power(&x,&exp,&xpow,&i);
|
||||
});
|
||||
if ((x != 0)||(exp != 0)){
|
||||
printf ("%.2lf в степени %d равно %lf\n", x, exp, xpow);}
|
||||
printf("Write: ");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void power (double *x, int *exp, double *xpow, int *i){
|
||||
if(*i<*exp){
|
||||
*xpow = (*xpow * *x);
|
||||
(*i)++;
|
||||
power(x, exp, xpow, i);
|
||||
}else({
|
||||
if (*exp<0) *xpow = (1 / *xpow);
|
||||
(*i) = 1;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user