|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- int main()
- {
- double power(double x, double y);
- double a, b, result;
- scanf("%f %f", &a, &b);
- result = power( a, b);
- printf("%f的%f次方是%f\n", a, b, result);
- }
-
-
- double power(double x, double y)
- {
- double s, t;
- int i, j ;
- j = y;
- s = y - j;
- if(s != 0)
- {
- t = x * s;
- }
-
- for( i=1; i<=j; i++)
- {
- t = t * y;
- }
- return t;
- }
复制代码
为何不能? - #include <stdio.h>
- double power(double x, int y)
- {
- double s = 1;
- if(y == 0)
- {
- if(x != 0)
- return 1;
- else
- return -1;
- }
- for(; y > 0; y--)
- s *= x;
-
- return s;
- }
- int main()
- {
- double a, b;
- scanf("%lf %lf", &a, &b);
- printf("%g", power(a,b));
- return 0;
- }
复制代码
|
|