Files
sibsutis/proglabs/lab7/8.c
T
Павел Родионов 2fca7b75f5 1
2025-11-13 18:21:23 +07:00

47 lines
879 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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;
}
}