Files
sibsutis/proglabs/lab7-8/8.c
T
oniic 2ed5553b96 Changes to be committed:
new file:   proglabs/lab7-8/10.c
	new file:   proglabs/lab7-8/11.c
	new file:   proglabs/lab7-8/12.c
	new file:   proglabs/lab7-8/13.c
	new file:   proglabs/lab7-8/14.c
	new file:   proglabs/lab7-8/15.c
	new file:   proglabs/lab7-8/16.c
	new file:   proglabs/lab7-8/17.c
	new file:   proglabs/lab7-8/18.c
	new file:   proglabs/lab7-8/19.c
	new file:   proglabs/lab7-8/3
	new file:   proglabs/lab7-8/5.c
	new file:   proglabs/lab7-8/6
	new file:   proglabs/lab7-8/6.c
	new file:   proglabs/lab7-8/7.c
	new file:   proglabs/lab7-8/8.c
	new file:   proglabs/lab7-8/9
	new file:   proglabs/lab7-8/9.c
	new file:   proglabs/lab7-8/test
	new file:   proglabs/lab7-8/tmp.out
2025-11-13 00:08:24 +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;
}
}