中秋节的故事英文50字:帮忙看看这两个C程序好吗?

来源:百度文库 编辑:高校问答 时间:2024/05/06 04:31:04
近来做了两道程序练习题,可是自己编完后这两个程序都有一个问题,看了好久也不知道究竟该怎么改,麻烦大家看看好吗?谢谢啦
第一个,是计算8个行星的距离的,调试程序时,报错是“ 需要逻辑0或非0在 BodeLaw 函数中”,不知道该怎么改,大虾看看:
/*File:AU.c*/

/*Function prototpye*/
float BodeLaw(int n);

main ()
{int i=8;
printf("This program is used to show you the distance \n");
printf("of the seven planet.\n");
switch(i){
case 1:
printf("Mercury %fAU\n",BodeLaw(1));break ;
case 2:
printf("Hesper %fAU\n",BodeLaw(2));break ;
case 3:
printf("Earth %fAU\n",BodeLaw(3));break ;
case 4:
printf("Mars %fAU\n",BodeLaw(4));break ;
case 5:
printf("? %fAU\n",BodeLaw(5));break ;
case 6:
printf("Jupiter %fAU\n",BodeLaw(6));break ;
case 7:
printf("Saturn %fAU\n",BodeLaw(7));break ;
case 8:
printf("Uranus %fAU\n",BodeLaw(8));break ;
getch();}
}

/*function :BodeLaw.*/
float BodeLaw(int n)
{ if(n==1)
return(1);
if(n==2)
return(3);
else
{for(n=3;n<=8;n++)
BodeLaw(n)=2*BodeLaw(n-1);
return((4+BodeLaw(n))/10);}
}

另一个是用连续逼进的算法求解立方根问题,调试程序时出现了三个错误:
/*File:CubeRoot.c */

#include <stdio.h>
#include "genlib.h"
#define Epsilon 0.000001

/*Function prototype */
double CubeRoot(double x);
bool ApproximatelyEqual(float x, float y);

main()
{double i;
printf("This program is used to show you the cube root \n");
printf("Enter a num :\n");
scanf("%f",&i);
printf("It's cube root is %f\n", CubeRoot(i));
}

/*Function :cube root .*/
double CubeRoot(double x)
{ double g;
if(x==0)return(0);
g=x;
while(!ApproximatelyEqual(x, g*g*g))
{ g=(g+x/(g*g))/2;
return(g);
}

/*Function :ApproximatelyEqual*/
bool ApproximatelyEqual(float x, float y)
{float z;
if ((fabs(x-y))/(z=(fabs(x)<fabs(y)?fabs(x):fabs(y)))<Epsilon)
return (TRUE);
}

请各位帮忙看看,谢谢啦

BodeLaw(n)=2*BodeLaw(n-1);
这个有问题,你把一个值付给一个函数,当然不行了

递归写得不对。
改成
要说清楚,n>3以后的算法才好改阿。