入门难,就算理解的写出了第一次,未必能写出第二次,就算写出了第二次也未必能保证每一个标点符号每一个变量都准确无误,至少是在理解的基础上未必能写的没有任何错误
写东西不熟练导致的根本就是写不出,要写,要练,要思考,人就是练出来的.
float readnumber(char f[],int *i)
{
{int k=0;
float x=0.0;
while(f[*i]>='0'&&whilef[*i]<='9')
{x=x*10+(f[*i]-'0');
(*i)++;}
if(f[*i]=='.')
{(*i)++;
whlie(f[*i]>='0'&&f[*i]<='9')
{x=x*10+(f[*i]-'0');
(*i)++;
k++;}
whlie(k!=0)
{x=x/10.0;
k=k-1;}
return x;
}
double evalpost(char f[])
{int i=0;
double obst[100];
double x1,x2,x;
int top=0;
whlie(f[i]!='#')
{if(f[i]>='0'&&f[i]<='9'||f[i]='.')
{obst[top]=readnumber(f,&i);
top++;
i++;}
else if(f[i]=='+')
{x1=obst[--top];
x2=obst[--top];
x=x1+x2;
top++;
i++;}
else if(f[i]=='-')
{x1=obst[--top];
x2=obst[--top];
x=x1-x2;
top++;
i++;}
else if(f[i]=='*')
{x1=obst[--top];
x2=obst[--top];
x=x1*x2;
top++;
i++;}
else if(f[i]=='/')
{x1=obst[--top];
x2=obst[--top];
x=x1/x2;
top++;
i++;}
return obst[0];
}
double postfix(char e[],char f[])
{char opst[100];
int i,j,t;
int top==0;
while(e[i]!='#')
{if(e[i]>='0'&&e[i]<='9'||e[i]=='.')
{f[j++]=e[i];}
else if(e[i]=='(')
{opst[top]=e[i];
top++;}
else if(e[i]==')')
{while(e[i]!='(')
{f[j++]=opst[top];
top--;
opst[top]=e[i];
top++;}
else if(e[i]=is_operation(e[i])
{while(opst[top]]>
写到这里吧,错误不少,也有写不出的,不行啊!