当前位置:
文档之家› 速算,简易计算器c语言代码,可实现加减乘除
速算,简易计算器c语言代码,可实现加减乘除
printf("|---------开始游戏请按'Y'-------------|\n");
printf("|---------退出游戏请按其他键-------------|\n");
printf("-----------------------------------------\n");
scanf("%c",&ch);
}
while(1)
{
printf("-----------------------------------------\n");
printf("|-----------欢迎来到速算24--------------|\n");
printf("|----------是否开始游戏?????------------|\n");
case '(':
{
if(b==')')
temp='=';
else
temp='<';
}break;
case ')':temp='>';break;
case '#':
{
if(b=='#')
temp='=';
else temp='<';
}break;
default break;
}
return temp;
#include"stdio.h"
#include"math.h"
#include"stdlib.h"
struct optrstyle
{
int top;
char stack[20];
}
struct opndstyle
{
int top;
int stack[20];
}
void main()
{
char ch;
if(ch=='Y' or ch=='y')
{
}
else
break;
}
}
int EvaluateExpression()
{
//算术表达式求值的算符优先算法。设OPTR和OPND分别为运算符栈和运算数栈,OP为运算符集合。
InitStack(OPTR);
Push(OPTR,'#');
InitStack(OPND);
{
S.top=-1;
}
int Pop1(Stack &S)
{
if(S.top==-1)
{
printf("stack is empty!");
exit (1);
}
ElemType temp=S.stack[S.top];
S.top--;
return temp;
}
int GetTop1(Stack &S)
Push(OPTR,c);
c = getchar();
break;
case '=': //脱括号并接收下一字符
Pop(OPTR,x); c = getchar();
break;
case '>': //退栈并将运算结果入栈
Pop(OPTR,theta);
Pop(OPND,b);
Pop(OPND,a);
{
char temp;
switch(a)
{
case '+','-':
{
if (b=='*' or b=='/' or b=='(')
temp='<';
else temp='>';
}break;
case '*','/':
{
if(b=='(')
temp='<';
else temp='>';
}break;
{
if(S.top==-1)
{
printf("stack is empty!");
exit (1);
}
return S.stack[S.top];
}
char Pop2(Stack &S)
{
if(S.top==-1)
{
printf("stack is empty!");
exit (1);
}
ElemType tem);
while(c!='#' || GetTop(OPTR)!='#')
{
if(!In(c,OP))
{
Push((OPND,c);
c = getchar();
} //不是运算符则进栈
else
switch(Precede(GetTop(OPTR),c))
{
case '<': //栈顶元素优先权低
Push(OPND,Operate(a,theta,b));
break;
}// switch
}// while
return GetTop(OPND);
}// EvaluateExpression
int changecard( char a[])
{
if()
}
void InitStack(Stack &S)
S.top--;
return temp;
}
char GetTop2(Stack &S)
{
if(S.top==-1)
{
printf("stack is empty!");
exit (1);
}
return S.stack[S.top];
}
char Precede(char a,char b)//算符优先级函数