速算,简易计算器c语言代码,可实现加减乘除费下载速算,简易计算器c语言代码,可实现加减乘除费下载
#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;
while(1)
{
printf("-----------------------------...
速算,简易计算器c语言代码,可实现加减乘除费下载
#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;
while(1)
{
printf("-----------------------------------------\n");
printf("|-----------欢迎来到速算24--------------|\n");
printf("|----------是否开始游戏?????------------|\n");
printf("|--------- 开始游戏请按'Y'-------------|\n");
printf("|--------- 退出游戏请按其他键-------------|\n");
printf("-----------------------------------------\n");
scanf("%c",&ch);
if(ch=='Y' or ch=='y')
{
}
else
break;
}
}
int EvaluateExpression()
{
// 算术表达式求值的算符优先算法。设 OPTR 和 OPND 分别为运算符栈和运算数栈,OP 为运算符集合。
InitStack(OPTR);
Push(OPTR,'#');
InitStack(OPND);
c = getchar();
while(c!='#' || GetTop(OPTR)!='#')
{
if(!In(c,OP))
{
Push((OPND,c);
c = getchar();
} // 不是运算符则进栈
else
switch(Precede(GetTop(OPTR),c))
{
case '<': // 栈顶元素优先权低
Push(OPTR,c);
c = getchar();
break;
case '=': // 脱括号并接收下一字符
Pop(OPTR,x); c = getchar();
break;
case '>': // 退栈并将运算结果入栈
Pop(OPTR,theta);
Pop(OPND,b);
Pop(OPND,a);
Push(OPND,Operate(a,theta,b));
break;
}// switch
}// while
return GetTop(OPND); }// EvaluateExpression
int changecard( char a[]) {
if()
}
void InitStack(Stack &S) {
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)
{
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 temp=S.stack[S.top];
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)//算符优先级函数 {
char temp;
switch(a)
{
case '+','-':
{
if (b=='*' or b=='/' or b=='(')
temp='<';
else temp='>';
}break;
case '*','/':
{
if(b=='(')
temp='<';
else temp='>';
}break;
case '(':
{
if(b==')')
temp='=';
else
temp='<';
}break;
case ')':temp='>';break;
case '#':
{
if(b=='#')
temp='=';
else temp='<';
}break;
default break;
}
return temp; }
本文档为【速算,简易计算器c语言代码,可实现加减乘除费下载】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。