上面的两楼我都没看出有什么不一样
路过 看看
#include<stdio.h> #include <conio.h> #include <math.h> #include <stdlib.h> double NumberParse(int temp_number_integer[],int temp_number_decemal[],int integer,int decemal); double NumberDeal(double number_one,double number_two,char deal); void main() { int temp_number_integer[200]; int temp_number_decemal[200]; int integer =0; int decemal =0; int sign =1; char deal; char type; double number_one=0; double number_two=0; int k=0; printf("这是一个加减乘除计算器,(输入格式为:4*5=):\n"); while((type=getch())!=27) { if(type==46) { printf("%c",'.'); sign =0; } else if(type>=49&&type<=57)//0到9 { printf("%d",type-48); if(sign==1) { temp_number_integer[integer] =(int)type-48; integer++; } else { temp_number_decemal[decemal] =(int)type-48; decemal++; } } else { if(((int)type)==10||type=='=') { number_two =NumberParse(temp_number_integer,temp_number_decemal,integer,decemal); integer =0; decemal =0; sign =1; printf("%c",'='); printf("%f",NumberDeal(number_one,number_two,deal)); printf("%c",10); number_one=0; number_two=0; } else if(k==0&&type==45) { printf("%c",type); k=1; } else { printf("%c",type); deal =type; if(number_one==0&&k==1) { number_one =(-1)*NumberParse(temp_number_integer,temp_number_decemal,integer,decemal); integer =0; decemal =0; sign =1; } else { number_one =NumberParse(temp_number_integer,temp_number_decemal,integer,decemal); integer =0; decemal =0; sign =1; } } } } exit(0); } double NumberParse(int temp_number_integer[200],int temp_number_decemal[200],int integer,int decemal) { int i=0; double number=0; while(integer>0) { number=number + temp_number_integer[i]*pow((double)10,integer-1); integer --; i++; } if(decemal!=0) { i=0; while(i<=decemal) { number =number + temp_number_decemal[i]*pow(0.1,i+1); decemal --; i++; } } return number; } double NumberDeal(double number_one,double number_two,char deal) { switch(deal) { case '+' :return number_one+number_two;break; case '-' :return number_one-number_two;break; case '*' :return number_one*number_two;break; case '/' :return number_one/number_two;break; } }