求高手帮忙用C编写一个计算器

||| 这个太简单了兄弟 newnode) { printf("/nMemory allocation failure =NULL) { top=stack; stack=stack->next; *value=top->data; free(top); return stack; } else *value=-1; } int empty(link stack) { if(stack==NULL) return 1; else return 0; } int is_operator(char operator) { switch (operator) { case '+': case '-': case '*': case '/': return 1; default:return 0; } } int priority(char operator) { switch(operator) { case '+': case '-' : return 1; case '*': case '/' : return 2; default: return 0; } } int two_result(int operator int value) { link newnode; newnode=(link) malloc(sizeof(s_list)); if( empty(operator)) { operand=pop(operand int operand1 int *value) { link top; if(stack empty(operator)) while(priority(expression[position])<= priority(operator->data)&& ='/n') { if(is_operator(expression[position])) { if( ='/0'&&expression[position] empty(operator)) { operator=pop(operator expression[position]); } else operand=push(operand operand2)); } operator=push(operator operand1 two_result(op &op); operand=push(operand &operand2); operator=pop(operator &operand1); operand=pop(operand int operand2) { switch(operator) { case '+':return(operand2+operand1); case '-':return(operand2-operand1); case '*':return(operand2*operand1); case '/':return(operand2/operand1); } } void main() { char expression[50]; int position=0; int op=0; int operand1=0; int operand2=0; int evaluate=0; printf("/nPlease input the inorder expression:"); gets(expression); while(expression[position] /n"); break; } return 0;}void menu_f(){printf("欢迎使用计算器:/n");printf("1.简单计算/n");printf("2.求平方根/n");printf("3.退出/n");printf("请输入您的选择:/n");}void SubMain_f(){int c;system("cls");printf("---菜单选择---/n");printf("1.加法/n");printf("2.减法/n");printf("3..除法/n");printf("4.乘法/n");printf("5.退回主菜单/n");printf("请输入您的选择:/n");scanf("%d" s;int main(){ int i; menu_f(); scanf("%d" n2 evaluate); getch(); } ||| #include<stdlib.h>#include<stdio.h>#include<math.h>#include <string.h>void SubMain_f();/*四则运算*/void SqRoot_f();/*平方根*/void CalcAdd_f();/*加法*/void CalcSub_f();/*减法*/void CalcDiv_f();/*除法*/void CalcMult_f();/*乘法*/void menu_f();/*主菜单*/int n1 expression &evaluate); printf("The expression [%s] result is '%d' " operand2)); } operand=pop(operand operand1 two_result(op &operand2); operand=push(operand &operand1); operand=pop(operand &op); operand=pop(operand expression[position]-48); position++; } while( "); break;}}void CalcAdd_f(){printf("请输入数字:/n");scanf("%d" &i);/*用户输入选择*/ switch(i) { case 1: SubMain_f(); break; case 2: SqRoot_f(); break; case 3: return 0; default:printf("输入有误 这个最经典的例子基本上C语言书都有 ||| 用VC++6.0 工具 或者 VS2005的C++画一个计算机的图形界面 然后代码就容易写了 只不过是一些算法和事件操作 ||| 额现在只能写简单的计算器 还有功能 科学计算器还没到家~你可以在百度上搜啊~狗狗搜索也比较好 ||| 如果不是作业的话直接下载个Mathematic 5.0用就行了 ||| 书上都有的啊 n1 &n1);s=sqrt(n1);printf("%d的平方根是%lf/n" s);printf("按回车键返回…/n");getchar();getchar();getchar();SubMain_f();}void SqRoot_f(){printf("请输入数字:/n");scanf("%d" n2 n1 &n2);s=n1*n2;printf("%d*%d=%d/n" &n1);scanf("%d" s);printf("按回车键返回…/n");getchar();getchar();getchar();SubMain_f();}void CalcMult_f(){printf("请输入数字:/n");scanf("%d" n2 n1 &n2);s=n1/n2;printf("%d/%d=%d/n" &n1);scanf("%d" s);printf("按回车键返回…/n");getchar();getchar();getchar();SubMain_f();}void CalcDiv_f(){printf("请输入数字:/n");scanf("%d" n2 n1 &n2);s=n1-n2;printf("%d-%d=%d/n" &n1);scanf("%d" s);printf("按回车键返回…/n");getchar();getchar();getchar();SubMain_f();}void CalcSub_f()/*减法*/{printf("请输入数字:/n");scanf("%d" n2 n1 &n2);s=n1+n2;printf("%d+%d=%d/n" &n1);scanf("%d" &c);switch(c){case 1:CalcAdd_f();break;case 2:CalcSub_f();break;case 3:CalcMult_f();break;case 4:CalcMult_f();break;case 5:return ;default :printf("输入有误 "); return NULL; } newnode->data=value; newnode->next=stack; stack=newnode; return stack; } link pop(link stack #include <stdio.h> /*库函数*/ struct s_node { int data; struct s_node *next; }; typedef struct s_node s_list; typedef s_list *link; link operator=NULL; link operand=NULL; link push(link stack 找个C语言的书 s);printf("按回车键返回…/n");getchar();getchar();getchar();menu_f();} ||| 什么样的
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值