C语言编一个计算的CODE
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 16:05:27
C语言编一个计算的CODE
比如 (25 - 3) / 11
After processing 25 the stack would have 25 on it.
After processing 3 the stack would have 25 and 3 on it (with 3 on top).
After processing - the stack would have 22 on it:The subtract operation pops the top two items from the stack,and then pushes the result of their subtraction onto the stack.Note the order of the operands for subtraction.
After processing 11 the stack would have 22 and 11 on it (with 11 on top).
After processing / the stack would have 2 on it.
Now that the input has all been processed,you would print out 2 followed by a newline
计算器包含+-*/
You will read input from stdin ; you will have a main function .Each line of input will be a separate expression which you should evaluate in the manner described above.You may use the function int atoi (const char * str); which is provided in stdlib.h in order to convert a string into an integer .
如果出现错误printf("error\n"); and then process the next line错误有以下三种
There are not enough items on the stack to process the operation (eg.+ with only one item).
There are too many items on the stack at the end of the expression (eg.1 2 3 +).
Division by 0.
那个例子 (25 - 3) / 11应该转换为25 3 - 11 /的形式
更多例子
input
16 2 2 + /
3 3 3 3 * * *
5 +
3 2 3 + + 2 3 + *
output
4
81
error
40
比如 (25 - 3) / 11
After processing 25 the stack would have 25 on it.
After processing 3 the stack would have 25 and 3 on it (with 3 on top).
After processing - the stack would have 22 on it:The subtract operation pops the top two items from the stack,and then pushes the result of their subtraction onto the stack.Note the order of the operands for subtraction.
After processing 11 the stack would have 22 and 11 on it (with 11 on top).
After processing / the stack would have 2 on it.
Now that the input has all been processed,you would print out 2 followed by a newline
计算器包含+-*/
You will read input from stdin ; you will have a main function .Each line of input will be a separate expression which you should evaluate in the manner described above.You may use the function int atoi (const char * str); which is provided in stdlib.h in order to convert a string into an integer .
如果出现错误printf("error\n"); and then process the next line错误有以下三种
There are not enough items on the stack to process the operation (eg.+ with only one item).
There are too many items on the stack at the end of the expression (eg.1 2 3 +).
Division by 0.
那个例子 (25 - 3) / 11应该转换为25 3 - 11 /的形式
更多例子
input
16 2 2 + /
3 3 3 3 * * *
5 +
3 2 3 + + 2 3 + *
output
4
81
error
40
逆波兰式的表达式计算么,和中缀表达式方式类似的,因为不需要处理括号和优先级,直接
一个堆栈就搞定了,
分析表达式 碰到数字 进栈 碰到符号 出栈2个数字 根据符号进行运算
运算结果再进栈 直到表达式分析结束, 最后栈顶就是结果,
碰到除0 直接放弃运算
如果分析结束 栈中数据不是1个那么就出错
再问: 能帮写下么 太小白了
再答: 自己写,都是基本的东西
一个堆栈就搞定了,
分析表达式 碰到数字 进栈 碰到符号 出栈2个数字 根据符号进行运算
运算结果再进栈 直到表达式分析结束, 最后栈顶就是结果,
碰到除0 直接放弃运算
如果分析结束 栈中数据不是1个那么就出错
再问: 能帮写下么 太小白了
再答: 自己写,都是基本的东西
C语言编一个计算的CODE
C语言编一个计算e的值的程序
C语言中,code uint8 a[] 里面的"code"是什么意思?
哪位高手帮我用c语言编一个计算圆的周长和面积
求编写一个函数,计算f(x,y)=x的y次幂 用C语言编的
如何用降阶法求解四阶行列式的计算,请帮我编一个C语言程序.
用C语言怎么编一个求和的程序?
谁能帮我编一个C语言程序?
编一个程序,输入X的值,按下列公式计算c语言题目编一个程序,输入X的值,按下列公式计算并输出Y的值并输出Y的值
C语言题“输入系数的有效值,计算一元二次方程的实根和虚根”怎么编?
C语言编个函数用作计算一组数的偶数之和并且输出偶数个数
用C 语言编程序计算平面上任意两点之间的距离.