读书人

求个程序希望高手帮忙,该怎么解决

发布时间: 2012-03-30 17:32:09 作者: rapoo

求个程序,希望高手帮忙
就是用VC编写一个计算器,能实现+-*/运算,还有,表达式由用户输入,并且可以合并两个同类项.

[解决办法]

C/C++ code
/*  an easy calculator  author He Zhengjun   2011-3-30*/#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#define MAX 20int pri(int);void initial();int stack[MAX]={0};int input[MAX]={0};int top=-1;int itop=-1;int flag[MAX]={0};int i=0;void main(){    char c[30];    printf("\n\n\n\t Welcome to use easy Calculate\t\n\t Don't input blanks in your input strings\n\t for it to work correctly\t\n \n\tThanks!\t\n");    printf("\tNOTICE:\n");    printf("\tq or Q mins quit the mini calculator\n");        while(1)    {        initial();        scanf("%s",c);                if(c[0]=='q' || c[0]=='Q')        {            char t;            printf("Do you want to quit?(y/n):");            fflush(stdin);            scanf("%c",&t);            if(t=='y' || t== 'Y')            {                break;            }else{                continue;            }        }        int len=strlen(c);                while(i<len)        {            if(c[i]==' ')            {                i++;                continue;            }            if(pri(c[i])>=0)            {                if(top==-1 || pri(stack[top])<pri(c[i]) || c[i]=='(')                {                    stack[++top]=c[i];                }                else                 {                    while(stack[top]!='(' && pri(m.D 

读书人网 >C语言

热点推荐