四则运算栈c语言程序,四则运算 c语言编程
滿意答案
ssxxdairi
2013.07.04
采納率:47%????等級:12
已幫助:7275人
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
int n=0;
char record[20];
float product();
float change();
float muli()
{
float summ;
summ=product();
while(record[n]=='-'||record[n]=='+')
{
switch(record[n])
{
case '+':n++;summ+=product();break;
case '-':n++;summ-=product();break;
}
}
return summ;
}
float product()
{
float sump;
sump=change();
while(record[n]=='*'||record[n]=='/')
{
switch(record[n])
{
case '*':n++;sump*=change();break;
case '/':n++;sump/=change();break;
}
}
return sump;
}
float change()
{
float sumc;
char? rec[20],i=0;
if(record[n]=='(')
{
n++;
sumc=muli();
}
if(record[n]==')')
n++;
while(isdigit(record[n])||record[n]=='.')
{
while(isdigit(record[n])||record[n]=='.')
rec[i++]=record[n++];
rec[i]='\0';
sumc=atof(rec);
}
return? sumc;
}
void main()
{
while(1)
{
n=0;
scanf("%s",record);
printf("%s=%g\n",record,muli());
}
}
30分享舉報
總結
以上是生活随笔為你收集整理的四则运算栈c语言程序,四则运算 c语言编程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 行业格局将改变?曝iPhone 16系列
- 下一篇: 华为nova10青春版上市!支持66W快