哪位帮忙用C语言设计一个多功能计算器

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:38:27
用C语言设计一个多功能计算器
实现功能:
1)具备整型数据、浮点型数据的算术(加、减、乘、除)运算功能。
依次输入第一个运算数、运算符(+,-,*,/),第二个运算数,然后输出结果。
结果可以作为下一个运算的第一运算数。按‘C’清屏,按‘X’退出。
例如:输入:2
+
5
输出:7
2)实现单运算符表达式计算的功能。
输入的操作数可以包含整数或浮点数。如果遇到错误的表达式,应输出错误提示信息。
输入表达式如下:
例如:输入:2+5
输出:7

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>

#define MAXOP 100
#define NUMBER '0'
#define MAXVAL 100
#define BUFSIZE 100
#define NAME 'n'

int getop(char s[]);
void push(double);
double pop(void);
int getch(void);
void ungetch(int c);
double atof(char s[]);
void mathfnc(char s[]);
void clear(void);

int sp = 0; double val[MAXVAL];
int bufp = 0; char buf[BUFSIZE];
int main(void)
{
int i, type, var = 0;
double op2, v;
char s[MAXOP];
double variable[26];

for(i = 0; i < 26; i++)
variable[i] = 0.0;

while ((type = getop(s)) != EOF) {
switch(type) {

case NUMBER :
push (atof(s));
break;

case NAME :<