求按要求用C语言作的一个计算器

有做好的请发我邮箱[email protected]
好用的话在加分
要求为设计一个多功能计算器
实现功能:
1)具备整型数据、浮点型数据的算术(加、减、乘、除)运算功能。
依次输入第一个运算数、运算符(+,-,*,/),第二个运算数,然后输出结果。
结果可以作为下一个运算的第一运算数。按‘C’清屏,按‘X’退出。
例如:输入:2
+
5
输出:7
2)实现单运算符表达式计算的功能。
输入的操作数可以包含整数或浮点数。如果遇到错误的表达式,应输出错误提示信息。
输入表达式如下:
例如:输入:2+5
输出:7

以下答案经测试无法编译啊 答案能否在修改下 现在提到200分了 请能者帮忙 最好不要太复杂 要个确认符合要求能编译构建的

计算器的c语言程序设计
一.功能概述:本程序能计算带二重括号的计算式的结果,如输入((3+2)*(3+2)+5)*((3+2)*(3+2)+5)*(5+5)= 将输出结果为9000
二.源程序:
#include<stdio.h>
int w;
double B[4][40];

shuru(char *pt)
{
int i=0,m;
do
{
*(pt+i)=getchar();
m=i;
i++;
}
while(*(pt+m)!='=');
*(pt+m)='+';
*(pt+m+1)='=';
}

tlchli(char *p)
{
int a,b;
if(*p=='-'||*p=='+')
{
for(b=0;*(p+b)!='=';b++)
;
for(;b>=0;b--)
*(p+b+1)=*(p+b);
*p='0';
}
else
{
for(a=1;*(p+a)!='=';a++)
{
if(*(p+a)=='-'||*(p+a)=='+')
{
if(*(p+a-1)=='('&&*(p+a+1)>='0'&&*(p+a+1)<='9')
{
for(b=0;*(p+a+b)!='=';b++)
;
for(;b>=0;b--)
*(p+a+b+1)=*(p+a+b);
*(p+a)='0';
a=(a+1);
}
}
}
}
}

jgh(double B[4][40],char *p)
{
int a,b,c=0,d,e,f,h,i,k,n,m;
double g=0,j=0;
for(a=0;a<4;a++)
for(b=0;b<40;b++)
B[a]=0;
for(d=0;*(p+d)!='=';d++)
{
if(*(p+d)=='+'||*(p+d)=='-'||*(p+d)=='*'||*(p+d)=='/')
{
if(*(p+d)=='+') B[3][c]='+';
if(*(p+d)=='-') B[3][c]='-';
if(*(p+d)=='*') B[3][c]='*';
if(*(p+d)=='/') B[3][c]='/';
if(*(p+d-1)==')'&&*(p+d-2)==')')
{
B[0][c]=')';
B[1][c]=')';
}
if(*(p+d-1)==')'&&*(p+d-2)!=')')
B[1][c]=')';
for(e=d-1;*(p+e)<'0'||*(p+e)>'9';e--)
;
for(f=e;*(p+f)!='.'&&(f>0)&&*(p+f)>='0'&&*(p+f)<='9';f--)
;
if(*(p+f)=='.')
{
for(h=f-1;(h>=0)&&*(p+h)>='0'&&*(p+h)<='9';h--)
;
h++;
if(*(p+h-1)=='('&&*(p+h-2)=='(')
{
B[0][c]='(';
B[1][c]='(';
}
if(*(p+h-1)=='('&&*(p+h-2)!='(')
B[1][c]='(';
for(i=h;*(p+i)>='0'&&*(p+i)<='9';i++)
g=(*(p+i)-48)+g*10.0;
for(k=f+1;*(p+k)>='0'&&*(p+k)<='9';k++)
;
k--;
for(n=k;*(p+n)>='0'&&*(p+n)<='9';n--)
j=(j/10.0+(*(p+n)-48)/10.0);
B[2][c]=(g+j);
g=j=0;
}
else
{
for(m=e;*(p+m)>='0'&&*(p+m)<='9';m--);
m++;
if(*(p+m-1)=='('&&*(p+m-2)=='(')
{
B[0][c]='(';
B[1][c]='(';
}
if(*(p+m-1)=='('&&*(p+m-2)!='(')
B[1][c]='(';
for(i=m;*(p+i)>='0'&&*(p+i)<='9';i++)
g=(*(p+i)-48)+g*10.0;
B[2][c]=g;
g=0;
}
c++;
}
}
w=(c-1);
}

qkh1(double B[4][40])
{
int a=1,b,c,d,e,f,j,k;
for(b=0;b<w;b++)
{
if(B[a]=='(')
{
for(c=b;B[a][c]!=')';c++)
;
for(d=b+1;B[a][d]!='('&&d<c;d++)
;
if(B[a][d]=='(')
k=d;
else
k=b;
B[a][k]=0;B[a][c]=0;
for(e=k;e<c;e++)
{
if(B[3][e]=='*')
{
B[2][e+1]=B[2][e]*B[2][e+1];
if(B[3][e-1]=='-'&&(e>0))
{
B[2][e]=0;
B[3][e]='-';
}
else
{
B[2][e]=0;
B[3][e]='+';
}

}
if(B[3][e]=='/')
{
B[2][e+1]=B[2][e]/B[2][e+1];
if(B[3][e-1]=='-'&&e>0)
{
B[2][e]=0;
B[3][e]='-';
}
else
{
B[2][e]=0;
B[3][e]='+';
}
}
}
for(f=k;f<c;f++)
{
if(B[3][f]=='+')
{
B[2][f+1]=B[2][f]+B[2][f+1];
B[2][f]=0;B[3][f]='+';
}
if(B[3][f]=='-')
{
B[2][f+1]=B[2][f]-B[2][f+1];
B[2][f]=0;B[3][f]='+';
}
}
b=c-1;
if(B[3][k-1]=='*'&&k>0)
{
for(;k<c;k++)
{
B[3][k]='*';
B[2][k]=1.0;
}
}
if(B[3][k-1]=='/'&&k>0)
{
for(;k<c;k++)
{
B[3][k]='/';
B[2][k]=1.0;
}
}
}
}
for(j=0;j<=w;j++)
{
if(B[1][j]!='('&&B[1][j]!=')')
B[1][j]=B[0][j];
}
}

qkh2(double B[4][40])
{
int a,b,c,d,e,f,j;
for(b=0;b<w;b++)
{
if(B[1]=='(')
{
for(c=b;B[1][c]!=')';c++)
;
B[1]=0;B[1][c]=0;
for(e=b;e<c;e++)
{
if(B[3][e]=='*')
{
B[2][e+1]=B[2][e]*B[2][e+1];
if(B[3][e-1]=='-'&&(e>0))
{
B[2][e]=0;
B[3][e]='-';
}
else
{
B[2][e]=0;
B[3][e]='+';
}
}
if(B[3][e]=='/')
{
B[2][e+1]=B[2][e]/B[2][e+1];
if(B[3][e-1]=='-'&&(e>0))
{
B[2][e]=0;
B[3][e]='-';
}
else
{
B[2][e]=0;
B[3][e]='+';
}
}
}
for(f=b;f<c;f++)
{
if(B[3][f]=='+')
{
B[2][f+1]=B[2][f]+B[2][f+1];
B[2][f]=0;B[3][f]='+';
}
if(B[3][f]=='-')
{
B[2][f+1]=B[2][f]-B[2][f+1];
B[2][f]=0;B[3][f]='+';
}
}
if(B[3][b-1]=='*'&&b>0)
{
for(;b<c;b++)
{
B[3]='*';
B[2]=1.0;
}
}
if(B[3][b-1]=='/'&&b>0)
{
for(;b<c;b++)
{
B[3]='/';
B[2]=1.0;
}
}
}
}
}

jshjg(double B[4][40])
{
int b,d,e,f;
for(e=0;e<w;e++)
{
if(B[3][e]=='*')
{
B[2][e+1]=B[2][e]*B[2][e+1];
if(B[3][e-1]=='-'&&e>0)
{
B[2][e]=0;
B[3][e]='-';
}
else
{
B[2][e]=0;
B[3][e]='+';
}
}
if(B[3][e]=='/')
{
B[2][e+1]=B[2][e]/B[2][e+1];
if(B[3][e-1]=='-'&&e>0)
{
B[2][e]=0;
B[3][e]='-';
}
else
{
B[2][e]=0;
B[3][e]='+';
}
}
}
for(f=0;f<w;f++)
{
if(B[3][f]=='+')
{
B[2][f+1]=B[2][f]+B[2][f+1];
B[2][f]=0;B[3][f]='+';
}
if(B[3][f]=='-')
{
B[2][f+1]=(B[2][f]-B[2][f+1]);
B[2][f]=0;B[3][f]='+';
}
}
}

shuchu(double B[4][40],char *p)
{
printf("answer %f\n",B[2][w]);
}

main()
{
char *p,A[100];
shuru(A);
p=&A[0];
tlchli(p);
jgh(B,p);
qkh1(B);
qkh2(B);
jshjg(B);
shuchu(B,p);
}

#include"string.h"
#include"graphics.h"
#include"conio.h"
#include"dos.h"
#include"time.h"
#include"stdlib.h"
#include"stdio.h"
#include"math.h"
/*调用一系列的库函数*/
int py;/*定义一个全局变量*/
void mode(int py)/*mode函数,用来设置的,来使用计算器的多种运算功能*/
{ double x1,x2,ans,ans2;
if(py<11)
{ printf("input x1,x2:");
scanf("%lf,%lf",&x1,&x2); }
else {printf("input x:");scanf("%lf",&x1);}
switch(py)
{ case 6 : ans=x1+x2;printf("=%.3lf",ans);break;
case 7 : ans=x1-x2;printf("=%.3lf",ans);break;
case 8 : ans=x1*x2;printf("=%.3lf",ans);break;
case 9 : ans=x1/x2;printf("=%.3lf",ans);break;
case 10 : ans=pow(x1,x2);printf("x^%.1lf=%.3lf",x2,ans);break;
case 11 : ans=sqrt(x1);printf("=%.3lf",ans);break;
case 12 : ans=sin(x1);ans2=cos(x1);printf("sin x=%.3lf,cos x=%.3lf",ans,ans2);break;
case 13 : ans=asin(x1);ans2=acos(x1);printf("asin x=%.3lf,acos x=%.3lf",ans,ans2);break;
}
getch();clrscr();
}
int join(char *ps) /*join函数是输入用户名和密码的,可于已注册的用户进行匹配,注册用户可使用高级功能*/
{ char name[30],pass[20];
int len,i;
printf("ID:");
scanf("%s",name);
printf("\npass word:");
scanf("%s",pass);
clrscr();
for(i=0;i<strlen(ps);i++)
if(pass[i]!=*(ps+i)) return 0;
return 1;
}

int menu(int pass)/*menu函数,菜单*/
{int py=6;char key=0;
gotoxy(1,4);
printf("MENU\n\n");
printf("ADD +\n");
printf("SUB -\n");
printf("MUL *\n");
printf("DIV /");
gotoxy(10,6);printf("<-");
if(pass) {gotoxy(1,10);printf("INV ^\n");
printf("EVO ~\n");
printf("SIN COS\n");
printf("ASIN ACOS\n");
printf("modify\n");
printf("QUIT"); }
else {gotoxy(1,10);printf("QUIT");}
while(key!=13) /*以下都是控制选择箭头的位子的语句*/
{ key=getch();
switch(key)
{ case 80 : gotoxy(10,py);printf(" ");if(!pass) py=py%5+6; else {++py;if(py==16) py=6;}break;

case 72 : gotoxy(10,py);printf(" ");--py; if(py==5) py=10+5*pass; break;
}
gotoxy(10,py);printf("<-");
}
return py;
}

main() /*主函数,关于函数分配和开始动画的语句*/
{ int gd=DETECT,gm,x=320,y=10,i,l=10,h=10,t,co=3,v=0;
int pass;
FILE *fp;char ps[20];
initgraph(&gd,&gm,"");/*初始化图形模式*/
registerbgidriver(EGAVGA_driver);
for(i=1;i<31;co=(co++%10),v++,y+=2+v,i++)
{ delay(9e10);cleardevice();
setcolor(co);
setfillstyle(1,co);
sector(x,y,0,360,l,h);/*画圆*/
}
for(i=1;i<300;i++)
{ setcolor(i%10);
circle(x,y,i);
delay(1000);/*延时*/
}
cleardevice();/*清屏*/
closegraph();
fp=fopen("file1","r");
if(fp==NULL) pass=1;
else {fgets(ps,20,fp);
pass=join(ps);}
ld: py=menu(pass);
if(py==pass*5+10) {clrscr();printf("bye bye!");getch();return 0;}
else if(py!=14){clrscr();mode(py);} else { fp=fopen("file1","w");
printf("\npass word:");
scanf("%s",ps);
fputs(ps,fp);
fclose(fp); getch();clrscr();
}
goto ld; /*函数内跳转*/
}
#include <stdio.h> /*库函数*/
struct s_node
{
int data;
struct s_node *next;
};
typedef struct s_node s_list;
typedef s_list *link;
link operator=NULL;
link operand=NULL;

link push(link stack,int value)
{
link newnode;

newnode=(link) malloc(sizeof(s_list));
if(!newnode)
{
printf("\nMemory allocation failure!!!");
return NULL;
}
newnode->data=value;
newnode->next=stack;
stack=newnode;
return stack;
}

link pop(link stack,int *value)
{
link top;
if(stack !=NULL)
{
top=stack;
stack=stack->next;
*value=top->data;
free(top);
return stack;
}
else
*value=-1;
}

int empty(link stack)
{
if(stack==NULL)
return 1;
else
return 0;

}

int is_operator(char operator)
{
switch (operator)
{
case '+': case '-': case '*': case '/': return 1;
default:return 0;
}
}

int priority(char operator)
{
switch(operator)
{
case '+': case '-' : return 1;
case '*': case '/' : return 2;
default: return 0;
}
}

int two_result(int operator,int operand1,int operand2)
{
switch(operator)
{
case '+':return(operand2+operand1);
case '-':return(operand2-operand1);
case '*':return(operand2*operand1);
case '/':return(operand2/operand1);
}
}

void main()
{
char expression[50];
int position=0;
int op=0;
int operand1=0;
int operand2=0;
int evaluate=0;

printf("\nPlease input the inorder expression:");
gets(expression);

while(expression[position]!='\0'&&expression[position]!='\n')
{
if(is_operator(expression[position]))
{
if(!empty(operator))
while(priority(expression[position])<= priority(operator->data)&&
!empty(operator))
{
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);
operator=pop(operator,&op);
operand=push(operand,two_result(op,operand1,operand2));
}
operator=push(operator,expression[position]);
}
else
operand=push(operand,expression[position]-48);
position++;
}
while(!empty(operator))
{
operator=pop(operator,&op);
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);

operand=push(operand,two_result(op,operand1,operand2));
}
operand=pop(operand,&evaluate);
printf("The expression [%s] result is '%d' ",expression,evaluate);
getch();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-03-29
拿以前做的稍微修改了下,主要使用string类来实现算式的运算的,支持的运算符有+-*/%^(乘方)(本打算扩充,但一直无时间),你可以参考下:

#include <iostream>
#include <string>
#include <sstream>
#include <cstddef>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <iomanip>
using namespace std;

template<class T>
class calculator
{
public:
calculator();
calculator(const calculator& cal);
calculator(const string& str);
calculator(const char* c_str);

template<class U>
calculator(const U& u);

string GetFormula();
T Result();

calculator operator = (const calculator& cal);

template<class X, class U>
X lexical_cast(U u);
private:
T dummyCal(const string& str);
T analyse();
T ops(T lhs, T rhs, char op);
string formula;
T value;
};

template<class T>
calculator<T>::calculator() : formula(""), value(T())
{
}

template<class T>
calculator<T>::calculator(const calculator& cal) : formula(cal.formula), value(cal.value)
{
}

template<class T>
calculator<T>::calculator(const string& str) : formula(str)
{
value = analyse();
}

template<class T>
calculator<T>::calculator(const char* c_str) : formula(string(c_str))
{
value = analyse();
}

template<class T>
template<class U>
calculator<T>::calculator(const U& u)
{
formula = u.formula;
value = analyse();
}

template<class T>
inline string calculator<T>::GetFormula()
{
return formula;
}

template<class T>
T inline calculator<T>::Result()
{
return value;
}

template<class T>
calculator<T> calculator<T>::operator = (const calculator& cal)
{
formula = cal.formula;
value = cal.value;
return *this;
}

template<class T>
T calculator<T>::ops(T lhs, T rhs, char op)
{
switch(op)
{
case '+':
return lhs + rhs;
case '-':
return lhs - rhs;
case '*':
return lhs * rhs;
case '/':
return lhs / rhs;
case '%':
return static_cast<T>(static_cast<int>(lhs) % static_cast<int>(rhs));
case '^':
return static_cast<T>(pow(static_cast<double>(lhs), static_cast<double>(rhs)));
default:
return 0;
}
}

template<class T>
T calculator<T>::dummyCal(const string& str)
{
string temp(str);
temp.erase(0, temp.find_first_not_of(' '));
size_t opPos;
while((opPos = temp.find_first_of("*/%^")) != string::npos
|| (opPos = temp.find_first_of("+-",1)) != string::npos)
{
size_t lhsValPos = temp.find_last_not_of("0123456789.", opPos - 1) == string::npos ?
0 : temp.find_last_not_of("0123456789.", opPos - 1) + 1;
if(temp[0] == '-' && temp.find_last_of("+-*/%^") != 0)
--lhsValPos;
size_t rhsValPos = temp.find_first_not_of("0123456789.", opPos + 2) == string::npos ?
temp.size() - 1 : temp.find_first_not_of("0123456789.", opPos + 2) - 1;
string LopR(temp, lhsValPos, rhsValPos - lhsValPos + 1);

istringstream isstrm(LopR);
T lhsVal, rhsVal;
char op;
isstrm >> lhsVal >> op >> rhsVal;
T result = ops(lhsVal, rhsVal, op);

temp.erase(lhsValPos, rhsValPos - lhsValPos + 1);
temp.insert(lhsValPos, lexical_cast<string>(result));

if(temp[0] == '-' && temp.find_last_of("+-*/%^") == 0)
break;
if(temp.find('e') != string::npos)
{
size_t ePos = temp.find('e');
if(temp.find_first_of("+-*/%^", ePos) == string::npos
&& (temp.find_last_of('-', ePos) == 0
|| temp.find_last_of("+-*/%^", ePos) == string::npos))
break;
}
}

return lexical_cast<T>(temp);
}

template<class T>
T calculator<T>::analyse()
{
string temp1 = formula;
while(temp1.find_first_of("()") != string::npos)
{
size_t rhsBracket = temp1.find(')');
size_t lhsBracket = temp1.rfind('(', rhsBracket);
string sResult(temp1, lhsBracket + 1, rhsBracket - lhsBracket - 1);

T partResult = dummyCal(sResult);

temp1.erase(lhsBracket, rhsBracket - lhsBracket + 1);
temp1.insert(lhsBracket, lexical_cast<string>(partResult));
}

istringstream sstrm(temp1);
T test;
while(sstrm >> test);
if(temp1 != lexical_cast<string>(test))
return dummyCal(temp1);

return lexical_cast<T>(temp1);
}

template<class T>
template<class X, class U>
X calculator<T>::lexical_cast(U u)
{
stringstream sstrm;
sstrm << u;
X x;
sstrm >> x;
return x;
}

void title()
{
cout.fill('=');
cout << setw(24) << '=' << "计算器" << setw(24) << '=' << '\n' << endl;
cout.fill(' ');
cout << setw(18) << ' ' << "C清屏, X退出, N继续" << setw(12) << ' '<< endl;
cout << "\n操作: 加 +\t减 -\t乘 *\t除 /\t模 %\t乘方 ^\n";
cout << "\n请输入任意计算式:\n";
}

int main()
{
title();
string formula;
int count = 1;
while(true)
{
cout << "\n式子" << count << " : ";
string input;
cin >> input;

if(input.find_first_not_of("CNXcnx0123456789.+-*/%^()") != string::npos)
{
cout << "输入中有错误, 请重新输入!\n";
cin.clear();
continue;
}

if(input.find_first_of("Cc") != string::npos)
{
system("cls");
formula.clear();
count = 1;
title();

}else if(input.find_first_of("Xx") != string::npos)
{
break;

}else
{
formula += input;
calculator<double> cal(formula);
++count;
cout << "结果" << count << " : " << formula << " = " << cal.Result() << endl;
formula = cal.lexical_cast<string>(cal.Result());
}
}
cout << "程序结束..." << endl;

//calculator<int> cal1("1+2+3+4");
//calculator<long> cal2("4*3*2*1");
//calculator<float> cal3("((1*3/2)+(4/(1+1)))*3");
//calculator<double> cal4("((1+3)*(20+4/6+(3-9)))^-2");
//cout << cal1.GetFormula() << " = " << cal1.Result() << '\n';
//cout << cal2.GetFormula() << " = " << cal2.Result() << '\n';
//cout << cal3.GetFormula() << " = " << cal3.Result() << '\n';
//cout << cal4.GetFormula() << " = " << cal4.Result() << endl;
}

打了注释那部分是我以前对算式的测试,你可以运行下看看。

以下是我测试的结果:

计算器
C清屏, X退出, N继续
(3/2+2)^3+(9*(2-5)-3)*2
(3/2+2)^3+(9*(2-5)-3)*2 = -17.125
请选择(C/X/N): n
+1
-17.125+1 = -16.125
请选择(C/X/N): n
/2
-16.125/2 = -8.0625
请选择(C/X/N): x
程序结束...本回答被提问者采纳
第2个回答  2007-03-25
我也有一个,你可以看看,如果那个地方不好的话你可以自己修改一下,里面还有详细的说明呢。呵呵!!!

#include<stdio.h>
#include<math.h>
/*预处理*/
#define a_size 10
#define in_size 10
#define elemtype int
#define null 0
char p[5][5]={ /*一个数组*/
{'>','>','<','<','>'},
{'>','>','<','<','>'},
{'>','>','>','>','>'},
{'>','>','>','>','>'},
{'<','<','<','<','='}
};
typedef struct /*定一个int SQ结构*/
{
elemtype *top; /*指针*/
elemtype *base;
int size; /*整*/
}sq; /*结构体名*/

create(sq *s) /*一个CREATE函数*/
{
s->base=(elemtype *)malloc(a_size * sizeof(elemtype)); /*结构体指针变量生明内存*/
if(!s->base) /*检查结构体指针量是否为真*/
return 0;
s->top=s->base; /*将base 的值传送给top*/
s->size=a_size; /*将a_size的值传送给size*/
return 1;
}
push(sq *s,elemtype e) /*一个PUSH函数*/
{
if(s->top-s->base==s->size) /*如果top-base的等于size*/
{
s->base=(elemtype *)realloc(s->base,(s->size+in_size)* sizeof(elemtype)); /*重设变量内存*/
if(!s->base)
return 0;
s->top=s->base+s->size;
s->size=s->size+in_size;
}
*s->top++=e;
return 1;
}
pop(sq *s,elemtype e) /*一个POP函数 */
{
if(s->top==s->base) /*如果top等于base*/
return 0;
e=*(--s->top);
}
int clearstack(sq *s) /*一个CLEARSTACK函数*/
{ /*SQ结构堆栈重设*/
s->top=s->base;
return 1;
}
int cmp(sq* s,int a,int b) /*一个CMP函数*/
{
if(s->top!=s->base) /*如果top不等于base*/
{
a=*(s->top-1); /*a等于a* top-1*/
}
else return 0;
return p[a][b]; /*如果等于,反回a,b到P字符数组*/
}
int switch_look(int y,int ysf,int x) /* 一个LOOK函数*/
{
switch(ysf)
{
case 0: return(y+x);break; /*计算公式*/
case 1: return(y-x);break;
case 2: return(y*x);break;
case 3: return(y/x);break;
default: return -1;
}
}
int empty(sq *s) /*一个EMPTY函数*/
{
int a;
a=*(s->top-1);
if(a==4)
return 0; /*检查是否超出计算组范围*/
}
main() /*C主函数模块,程序的起始点*/
{
int i=0,j,m=0,e,x,y,z=0,c_int,top_c,count_1=0,count_2=0,in[200],count; /*变量申明*/
sq *S,*N;
char c[200],f_h,catch; /*变量申明*/
create(S); /*函数调用*/
create(N);
push(S,4);
clrscr(); /*清屏*/
for(count=0;count<80;count++) /*数值检查*/
{
printf("*");
}
for(count=0;count<55;count++) printf(" ");
printf("version number:1.0.1n");
scanf("%s",&c);
do
{
if(c[i]=='+'||c[i]=='-'||c[i]=='*'||c[i]=='/')
{
switch(c[i])
{
case '+': c_int=0;break; /*用户所输入的字符检查*/
case '-': c_int=1;break;
case '*': c_int=2;break;
case '/': c_int=3;break;
case '':c_int=4;break;
default : return -1;
}
f_h=cmp(S,top_c,c_int); /*赋值*/
if(f_h=='>')
{
x=pop(N,e);
y=pop(N,e);
j=pop(S,e);
z=switch_look(y,j,x);
push(N,z);
push(S,c_int);
i++;
}
else
{
push(S,c_int); /*函数调用*/
i++;
}
}
else
{
in[count_1]=(int)c[i]-48;
count_1++;
i++;
if(c[i]=='+'||c[i]=='-'||c[i]=='*'||c[i]=='/'||c[i]=='') /*用户所输入的字符检查*/
{
for(count_2=0;count_2<count_1;count_2++)
{
m=m+in[count_2]*pow10(count_1-count_2-1);
}
push(N,m);
count_1=0;
m=0;
}
}
} /*下面的自己看^_^*/
while(c[i]!='');
while(empty(S)!=0)
{
x=pop(N,e);
y=pop(N,e);
j=pop(S,e);
z=switch_look(y,j,x);
push(N,z);
}
printf("THE ANSWER IS : %dn",z);
clearstack(N);
clearstack(S);
loop:
printf(" to be continue? (Y/N) n");
catch=getch();
if(catch=='y')
main();
else if(catch=='n') goto end;
else goto loop;
end:
printf(" Thank you for using it!n");
getch();
}
第3个回答  2007-03-26
我已经把代码发到你邮箱里了,有什么问题给我发信息。
第4个回答  2007-03-26
汗!我刚刚想去学C语言!! 天啊! 着叫我信心少了一多半