这个程序调试的时候老说变量top1和top2未定义,但是明明定义了的啊,然后我干脆就加上一句 int top1,top2;这句话在前面,就调得通了,但运行菜单2的时候就会出现错误:Flooting point error:Domain 这种错误我以前好象也遇到过,就好象用了double或flot这类型的时候就容易出现这种错误,请问为什么啊,能给个详细的解答么 ?谢谢了
主程序如下:
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "math.h"
#include "string.h"
#include "conio.h"
#include "stdlib.h"
#define y 0.0000001
struct xishu
{int coef[100];
int top1;
}p;
struct zhishu
{int expn[100];
int top2;
}q;
shuru()
{ double a;
int b;
printf("please input the coef and expn\n");
while(1)
{ scanf("%lf%d",&a,&b);
printf("!!!!!!\n");
if(b==-1) break;
p.coef[top1]=a; q.expn[top2]=b;
top1++; top2++;
}
return;
}
double duoxiangshi(double x)
{ int m=1,n=0;
int i;
while(top1!=0)
{ for(i=0;i<q.expn[top2-1];i++)
m*=x;
m*=p.coef[top1-1];
n+=m;
m=1;
top1--; top2--;
}
return n;
}
double jisuan()
{ double x1=1,x2=0,x3[100];
int i=0;
x3[0]=0;
while(fabs(x2-x1)>y||fabs(x2-x1)==y)
{ x1=duoxiangshi(x3[i]);
x2=duoxiangshi(x1);
x3[i+1]=x2-(x2+x1)*(x2+x1)/(x2-2*x1+x3[i]);
i++;
}
return x3[i];
}
main()
{ int nem;
while(1)
{
printf("/*********************************************************/\n");
printf("/**************** 1.shuru ********************************/\n");
printf("/**************** 2.jisuan *******************************/\n");
printf("/**************** 3.dayin ********************************/\n");
printf("/**************** 4.exit *********************************/\n");
printf("your choice is what ?(1-4)\n");
scanf("%d",&nem);
switch(nem)
{ case 1: shuru();
break;
case 2: jisuan();
printf("has finished !!!\n");
break;
case 3: printf("the result is %d\n",jisuan());
break;
case 4: break;
}
if(nem==4) break;
}
}