C语言小学生英语CAI,c语言小学生数学CAI系统

匿名用户

1级

2013-07-18 回答

#include

#include

#include

#include

#define MaxQSize 80

float qlist[MaxQSize],qlist1[MaxQSize],qlist2[MaxQSize]; //定义三个全局队列

int front=0,rear=0,front1=0,front2=0,rear1=0,rear2=0,count=0,count1=0,count2=0;//定义三个队列头结点、尾结点、数据个数

main()

{

char c[80];

void Enter(float),pop(),ClearStack();

printf("input string:(n:sin,o:cos,s:sqrt)\n");

while(gets(c),*c!='q' ||*c!='Q')

{

switch(*c)

{

case '+':

case '*':

case 's':

case 'n': //求SIN

case 'o': //求COS

case '/': //将符号入第一个队列

{

if(count==MaxQSize)

{

printf("Quere overflow!");

exit(1);

}

count++;

qlist[rear]=*c;

rear=(rear+1)%MaxQSize;

break;}

case '-':

{

if(strlen(c)>1) //如果是负号,则将负号和数一起入第二个队列

Enter(atof(c));

else //否则,说明是减号,入第一队列

if(count==MaxQSize)

{

printf("Quere overflow!");

exit(1);

}

...#include

#include

#include

#include

#define MaxQSize 80

float qlist[MaxQSize],qlist1[MaxQSize],qlist2[MaxQSize]; //定义三个全局队列

int front=0,rear=0,front1=0,front2=0,rear1=0,rear2=0,count=0,count1=0,count2=0;//定义三个队列头结点、尾结点、数据个数

main()

{

char c[80];

void Enter(float),pop(),ClearStack();

printf("input string:(n:sin,o:cos,s:sqrt)\n");

while(gets(c),*c!='q' ||*c!='Q')

{

switch(*c)

{

case '+':

case '*':

case 's':

case 'n': //求SIN

case 'o': //求COS

case '/': //将符号入第一个队列

{

if(count==MaxQSize)

{

printf("Quere overflow!");

exit(1);

}

count++;

qlist[rear]=*c;

rear=(rear+1)%MaxQSize;

break;}

case '-':

{

if(strlen(c)>1) //如果是负号,则将负号和数一起入第二个队列

Enter(atof(c));

else //否则,说明是减号,入第一队列

if(count==MaxQSize)

{

printf("Quere overflow!");

exit(1);

}

count++;

qlist[rear]=*c;

rear=(rear+1)%MaxQSize;

break;}

case '=':

pop(); //显示结果

break;

case 'c':

ClearStack();

break;

case 'q':

ClearStack();

exit(1);

default:

Enter(atof(c));

break;

}

}

return 0;

}

void Enter(float num) //将数据入第二个队列

{

if(count1==MaxQSize)

{

printf("Queue overflow!\n");

exit(1);

}

count1++;

qlist1[rear1]=num;

rear1=(rear1+1)%MaxQSize;

}

void ClearStack() //将三个队列清空

{

count=0;

count1=0;

)%MaxQSize;

QInsert(number);

}

break;

case '-':

if(count2==0)

{

num2=QFront1();

number=num1-num2;

printf("number=%f\n",number);

QInsert(number);

}

else

{

number=qlist2[front2]-num1;

printf("number=%f\n",number);

front2=(front2+1)%MaxQSize;

QInsert(number);

}

break;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值