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