当前位置:首页 » 编程语言 » c语言计算器编程代码

c语言计算器编程代码

发布时间: 2022-05-21 06:57:27

c语言编写简易计算器程序

C语言编写计算器

  • 我们可以用printf和scanf函数输出结果和获取用户的输入。需要<stdio.h>头文件。scanf函数在读取数据的时候不需要再一行上输入每个数据,只要数据和数据之间留出空白就可以了。先声明两个变量number1和number2,operation变量用来存储运算符。用scanf函数获取这两个数字和运算符。分别用%lf %c %lf

Ⅱ 计算器c语言代码

你这个代码的问题太多了,下面已经给你一一改过来了,并且编译运行通过了,自己比较一下:
你原先的错误都给你标出来了:

#include<stdio.h>

void displaymenu() //这个函数应该放在main函数外面进行定义
{
printf("\n\n*****************************\n");
printf("* 1.加法 *\n");
printf("* 2.?法 *\n");
printf("* 3.乘法 *\n");
printf("* 4.除法 *\n");
printf("* 5.求余 *\n");
printf("* 6.?乘 *\n");
printf("* 7.累加 *\n");
printf("* 8.?束 *\n");
printf("*****************************\n");

printf("????型<1,2,3,4,5,6,7,8>?\n");
}

main()
{
while(1) //这里应该是while(1),以实现循环的执行
{
displaymenu(); //这里原先笔误成menu()了,应该是displaymenu()

int a=0;
scanf("%d",&a);
switch(a)
{
case 1:
{//int i=0,j=0,add=0; 这里少定义了一个sum=0;
int i=0,j=0,add=0,sum=0;
scanf("%d%d",&i,&j);
sum=i+j;
printf("add=%d\n",sum);
};break;
case 2:
{int i=0,j=0,sub=0;
scanf("%d%d",&i,&j);
sub=i-j;
printf("sub=%d\n",sub);
};break;
case 3:
{int i=0,j=0,multi=0;
scanf("%d%d",&i,&j);
multi=i*j;
printf("multi=%d\n",multi);
};break;
case 4:
{int i=0,j=0;
float divide=0;
scanf("%d%d",&i,&j);
divide=i/j;
if(j=0)
printf("erro\n");
else
printf("divide=%lf\n",divide);
};break;
case 5:
{int i=0,j=0,arith_compliment=0; //这里原先的arith-compliment,不是C语言的合法变量名(变量名中不能有“-”)
scanf("%d%d",&i,&j);
arith_compliment=i%j;
printf("arith-compliment=%d\n",arith_compliment);
};break;
case 6:
{int i=0;
float fac=1.0;
for(i=1;i<=9;i++)
fac=fac*i;
printf("\n");
printf("fac=%lf",fac);
};break;
case 7:
{int i=0,sum_N=0;
for(i=0;i<=9;i++)
sum_N=sum_N+i;
printf("\n");
printf("sum_N=%d",sum_N);
};break;
}
}
}

Ⅲ c语言编写“多功能计算器”的代码

#include<stdio.h>
#include<windows.h>
#include<math.h>
double
EPS=10E-6;
double
sum(double
a,double
b)
{
return
a+b;
}
double
sub(double
a,double
b)
{
return
a-b;
}
double
mul(double
a,double
b)
{
return
a*b;
}
double
divv(double
a,double
b)
{
return
a/b;
}
int
rem(int
a
,
int
b)
{
return
a%b;
}
int
addnumber(int
c,int
d)
{
int
sum=0;
for(int
i=c;i<=d;i++)
{
sum+=i;
}
return
sum;
}
int
factor(int
n)
{
int
f=1;
for(int
i=1;i<=n;i++)
{
f*=i;
}
return
f;
}
void
displaymenu()
{
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\n");
printf("*############高级计算器############*
\n");
printf("************************************
\n");
printf("*
①加法运算
*
\n");
printf("*
②减法运算
*
\n");
printf("*
③乘法运算
*
\n");
printf("*
④除法运算
*
\n");
printf("*
⑤取余运算
*
\n");
printf("*
⑥累加运算
*
\n");
printf("*
⑦阶乘运算
*
\n");
printf("*
⊙结束运算
*
\n");
printf("************************************
\n");
printf("************************************
\n");
}
void
main()
{
int
c,d;
/*用于做四则运算的两个数值的说明*/
double
a,b;
/*用来做累加函数的两个参数值的说明*/
int
intresult;
double
result;
/*用于保存表单运算中函数的返回值*/
int
choice;
displaymenu();/*保存用户选择项目菜单项*/
while(1)
{
printf("请选择你所进行运算项目的符号:");
scanf("%d",&choice);
switch(choice)
{
case
1:
/*加法计算*/
printf("请输入两个数字:");
scanf("%lf%lf",&a,&b);
result=sum(a,b);
printf("%lf+%lf的计算结果是:%lf\n",a,b,result);
break;
case
2:
/*减法计算*/
printf("请输入两个数字:");
scanf("%lf%lf",&a,&b);
result=sub(a,b);
printf("%lf-%lf的计算结果是:%lf\n",a,b,result);
break;
case
3:
/*乘法计算*/
printf("请输入两个数字:");
scanf("%lf%lf",&a,&b);
result=mul(a,b);
printf("%lf*%lf的计算结果是:%lf\n",a,b,result);
break;
case
4:
/*除法计算*/
{
scanf("%lf%lf",&a,&b);
if(b-0.0<EPS)
printf("数字错误\n");
else
{
printf("请输入两个数字:");
result=divv(a,b);
printf("%lf/%lf的计算结果是:%lf\n",a,b,result);
}
break;
}
case
5:
/*取余计算*/
printf("请输入两个数字:");
scanf("%d%d",&c,&d);
result=rem(c,d);
printf("%d
%
%d的计算结果是:%d\n",c,d,result);
break;
case
6:
/*累加计算*/
printf("请输入两个整数");
scanf("%d%d",&c,&d);
intresult=addnumber(c,d);
printf("%d-%d的累加计算结果是:%d\n",c,d,intresult);
break;
case
7:
//阶乘计算
{
printf("请输入一个大于0小于10的整数字");
scanf("%d",&c);
if(c<0||c>10)
{
printf("请输入一个大于0小于10的整数字,数据错误。\n");
break;
}
intresult=factor(c);
printf("%d的阶乘计算结果是:%d\n",c,intresult);
break;
}
case
0:
printf("谢谢使用。欢迎下次再用。\n");
return
;
default:
printf("选择错误,程序结束\n");
break;
}
}
}

Ⅳ C语言 要求编写一个简单计算器的程序

#include<stdio.h>
voidmain(){floatx,y,z;charc;
scanf("%f%c%f",&x,&c,&y);
switch(c){
case'+':z=x+y;break;
case'-':z=x-y;break;
case'*':z=x*y;break;
case'/':z=(y==0)?(0):(x/y);break;
default:z=0;break;
}
printf("%f%c%f=%f ",x,c,y,z);
}

Ⅳ 用c语言编写一个简单计算器程序

#include<stdio.h>//计算器

voidmenu()//自定义的菜单界面

printf("--------------------\n");

printf("请输入你的选择\n");

printf("1.+\n");

printf("2.-\n");

printf("3.*\n");

printf("4./\n");

printf("--------------------\n");

intmain()

inti=0;

intj=0;

intnum=0;//计算结果存放在nun

intselect=0;//选择的选项存放在select

do//do-while先执行再判断循环条件,即可实现重复计算功能

menu();//打印出菜单界面

scanf("%d",&select);//输入你的选项

printf("请输入计算值:");

scanf("%d%d",&i,&j);//输入要计算的数值

switch(select)

case1:

printf("%d+%d=%d\n",i,j,num=i+j);//实现加法功能

break;

case2:

printf("%d-%d=%d\n",i,j,num=i-j);//实现减法功能

break;

case3:

printf("%d*%d=%d\n",i,j,num=i*j);//实现乘法功能

break;

case4:

printf("%d-%d=%d\n",i,j,num=i/j);//实现除法功能

break;

default:

printf("输入有误重新选择");

break;

}while(select);

return0;

运行结果:

(5)c语言计算器编程代码扩展阅读:

return表示把程序流程从被调函数转向主调函数并把表达式的值带回主调函数,实现函数值的返回,返回时可附带一个返回值,由return后面的参数指定。

return通常是必要的,因为函数调用的时候计算结果通常是通过返回值带出的。如果函数执行不需要返回计算结果,也经常需要返回一个状态码来表示函数执行的顺利与否(-1和0就是最常用的状态码),主调函数可以通过返回值判断被调函数的执行情况。

Ⅵ 用C语言编计算器程序

#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "math.h"

//expression evaluate
#define iMUL 0
#define iDIV 1
#define iADD 2
#define iSUB 3
#define iCap 4
//#define LtKH 5
//#define RtKH 6

#define MaxSize 100
void iPush(float);
float iPop();
float StaOperand[MaxSize];
int iTop=-1;
//
char Srcexp[MaxSize];
char Capaexp[MaxSize];
char RevPolishexp[MaxSize];
float NumCapaTab[26];
char validexp[]="*/+-()";
char NumSets[]="0123456789";
char StackSymb[MaxSize];
int operands;
//
void NumsToCapas(char [], int , char [], float []);
int CheckExpress(char);
int PriorChar(char,char);
int GetOperator(char [], char);
void counterPolishexp(char INexp[], int slen, char Outexp[]);
float CalcRevPolishexp(char [], float [], char [], int);

void main()
{
int ilen;
float iResult=0.0;
printf("enter a valid number string:\n");
memset(StackSymb,0,MaxSize);
memset(NumCapaTab,0,26); //A--NO.1, B--NO.2, etc.
gets(Srcexp);
ilen=strlen(Srcexp);
//printf("source expression:%s\n",Srcexp);
NumsToCapas(Srcexp,ilen,Capaexp,NumCapaTab);
printf("Numbers listed as follows:\n");
int i;
for (i=0; i<operands; ++i)
printf("%.2f ",NumCapaTab[i]);
printf("\nCapaexp listed in the following:\n");
printf("%s\n",Capaexp);
ilen=strlen(Capaexp);
counterPolishexp(Capaexp,ilen,RevPolishexp);
printf("RevPolishexp:\n%s\n",RevPolishexp);
ilen=strlen(RevPolishexp);
iResult=CalcRevPolishexp(validexp, NumCapaTab, RevPolishexp,ilen);
printf("\ncounterPolish expression:\n%s%.6f\n",Srcexp,iResult);

}

void iPush(float value)
{
if(iTop<MaxSize) StaOperand[++iTop]=value;

}

float iPop()
{
if(iTop>-1)
return StaOperand[iTop--];
return -1.0;
}

void NumsToCapas(char Srcexp[], int slen, char Capaexp[], float NumCapaTab[])
{
char ch;
int i, j, k, flg=0;
int sign;
float val=0.0,power=10.0;
i=0; j=0; k=0;
while (i<slen)
{
ch=Srcexp[i];
if (i==0)
{
sign=(ch=='-')?-1:1;
if(ch=='+'||ch=='-')
{
ch=Srcexp[++i];
flg=1;
}
}
if (isdigit(ch))
{
val=ch-'0';
while (isdigit(ch=Srcexp[++i]))
{
val=val*10.0+ch-'0';
}
if (ch=='.')
{
while(isdigit(ch=Srcexp[++i]))
{
val=val+(ch-'0')/power;
power*=10;
}
} //end if
if(flg)
{
val*=sign;
flg=0;
}
} //end if
//write Capaexp array
// write NO.j to array
if(val)
{
Capaexp[k++]='A'+j;
Capaexp[k++]=ch;
NumCapaTab[j++]=val; //A--0, B--1,and C, etc.
}
else
{
Capaexp[k++]=ch;
}
val=0.0;
power=10.0;
//
i++;
}
Capaexp[k]='\0';
operands=j;
}

float CalcRevPolishexp(char validexp[], float NumCapaTab[], char RevPolishexp[], int slen)
{
float sval=0.0, op1,op2;
int i, rt;
char ch;
//recursive stack
i=0;
while((ch=RevPolishexp[i]) && i<slen)
{
switch(rt=GetOperator(validexp, ch))
{
case iMUL: op2=iPop(); op1=iPop();
sval=op1*op2;
iPush(sval);
break;
case iDIV: op2=iPop(); op1=iPop();
if(!fabs(op2))
{
printf("overflow\n");
iPush(0);
break;
}
sval=op1/op2;
iPush(sval);
break;
case iADD: op2=iPop(); op1=iPop();
sval=op1+op2;
iPush(sval);
break;
case iSUB: op2=iPop(); op1=iPop();
sval=op1-op2;
iPush(sval);
break;
case iCap: iPush(NumCapaTab[ch-'A']);
break;
default: ;
}
++i;
}
while(iTop>-1)
{
sval=iPop();
}
return sval;
}

int GetOperator(char validexp[],char oper)
{
int oplen,i=0;
oplen=strlen(validexp);
if (!oplen) return -1;
if(isalpha(oper)) return 4;
while(i<oplen && validexp[i]!=oper) ++i;
if(i==oplen || i>=4) return -1;
return i;
}

int CheckExpress(char ch)
{
int i=0;
char cc;
while((cc=validexp[i]) && ch!=cc) ++i;
if (!cc)
return 0;
return 1;

}

int PriorChar(char curch, char stach)
{
//栈外优先级高于(>)栈顶优先级时,才入栈
//否则(<=),一律出栈
if (curch==stach) return 0; //等于时应该出栈
else if (curch=='*' || curch=='/')
{
if(stach!='*' && stach!='/')
return 1;
}
else if (curch=='+' || curch=='-')
{
if (stach=='(' || stach==')')
return 1;
}
else if (curch=='(')
{
if (stach==')')
return 1;
}
return 0;
}

void counterPolishexp(char INexp[], int slen, char Outexp[])
{
int i, j, k,pr;
char t;
i=0;
j=k=0;
while (INexp[i]!='=' && i<slen)
{
if (INexp[i]=='(')
StackSymb[k++]=INexp[i];
//iPush(*(INexp+i));
else if(INexp[i]==')')
{
//if((t=iPop())!=-1)
while((t=StackSymb[k-1])!='(')
{
Outexp[j++]=t;
k--;
}
k--;
}
else if (CheckExpress(INexp[i])) // is oparator
{
// printf("operator %c k=%d\n",INexp[i],k);
while (k)
{
// iPush(*(INexp+i));
if(pr=PriorChar(INexp[i],StackSymb[k-1]))
break;
else
{
//if ((t=iPop())!=-1)
t=StackSymb[k-1]; k--;
Outexp[j++]=t;
}
} //end while
StackSymb[k++]=INexp[i]; //common process
}
else //if() 变量名
{
// printf("operand %c k=%d\n",INexp[i],k);
Outexp[j++]=INexp[i];
}
i++; //
}
while (k)
{
t=StackSymb[k-1]; k--;
Outexp[j++]=t;
}
Outexp[j]='\0';
}

Ⅶ C语言程序设计简易计算器

1、首先,打开Vs 2010,如图。

2、找到左上角的新建并点击,给文件为简单计算器,单击确定。

3、点击下一步,注意勾选空项目,点击下一步,点击完成。

4、点击左侧的源文件,右击选择“添加—>项目”,选择C++文件,命名为简单计算器,因为是C程序,注意后缀名要加上.c,点击确定完成文件新建工作。

5、输入以下代码,好了,一个简单的计算器便做好了

Ⅷ 用c语言编写计算器

#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,int value)
{
link newnode;

newnode=(link) malloc(sizeof(s_list));
if(!newnode)
{
printf("\nMemory allocation failure!!!");
return NULL;
}
newnode->data=value;
newnode->next=stack;
stack=newnode;
return stack;
}

link pop(link stack,int *value)
{
link top;
if(stack !=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 operand1,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]!='\0'&&expression[position]!='\n')
{
if(is_operator(expression[position]))
{
if(!empty(operator))
while(priority(expression[position])<= priority(operator->data)&&
!empty(operator))
{
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);
operator=pop(operator,&op);
operand=push(operand,two_result(op,operand1,operand2));
}
operator=push(operator,expression[position]);
}
else
operand=push(operand,expression[position]-48);
position++;
}
while(!empty(operator))
{
operator=pop(operator,&op);
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);

operand=push(operand,two_result(op,operand1,operand2));
}
operand=pop(operand,&evaluate);
printf("The expression [%s] result is '%d' ",expression,evaluate);
getch();
}

Ⅸ c语言编程…急求一个“计算器”代码 错误要最少,每句代码后还要有中文注释

#include<stdio.h>
int
main()
{
int
a,b,d;
char
c;
int
fun(int
a,char
c,int
b);
printf("请输入计算式(如:3
+
2
):");
scanf("%d%c%d",&a,&c,&b);
d=fun(a,c,b);
if(d==99999)
printf("字符输入错误!");
else
printf("%d%c%d=%d",a,c,b,d);
fflush(stdin);
getchar();
return
0;
}
int
fun(int
a,char
c,int
b)
{
return
c=='+'?a+b:(c=='-'?a-b:(c=='*'?a*b:(c=='/'?a/b:99999)));
}
绝对经典的计算器,数据必须是整型哦

Ⅹ 用C语言编写一个计算器程序,实现加,减,乘,除,求平方根(正数),倒数等功能.

#include<iostream>
#include<cmath>
#include<string>
using
namespace
std;
const
double
pi
=
3.14159265;
const
double
e
=
2.718281828459;
const
int
SIZE
=
1000;
typedef
struct
node//为了处理符号而建立的链表(如:
1+(-2))
{
char
data;
node
*next;
}node;
typedef
struct
stack_num//存储

的栈
{
double
*top;
double
*base;
}stack_num;
typedef
struct
stack_char//存储
运算符号
的栈
{
char
*top;
char
*base;
}stack_char;
stack_num
S_num;//定义
stack_char
S_char;//定义
char
fu[18]
=
{'\n',
')',
'+',
'-',
'*',
'/',
'%',
'^',
'Q',
'L',
'C',
'S',
'T',
'c',
's',
't',
'('};
int
compare[1000];//表现出各运算符号的优先级
double
shu[1000];//存储
"数"
的数组
double
dai_result;//运算的结果,是为了处理
M
运算(简介函数里有M的定义)
int
biao
=
0;//和dia_result
一样,为了处理
M
运算
char
line[SIZE];//输入的所要计算的表达式
void
init()//初始化
{
compare[fu[0]]
=
-2;//用数字的大小表现出符号的优先级
compare[fu[1]]
=
-1;
compare[fu[2]]
=
2;
compare[fu[3]]
=
2;
compare[fu[4]]
=
4;
compare[fu[5]]
=
4;
compare[fu[6]]
=
4;
compare[fu[7]]
=
5;
for(int
i
=
8;
i
<=
15;
i++)
compare[fu[i]]
=
6;
compare[fu[16]]
=
7;
S_num.base
=
(double*)malloc(sizeof(double)*SIZE);//为栈开辟空间
S_char.base
=
(char*)malloc(sizeof(char)*SIZE);//同上
S_num.top
=
S_num.base;
S_char.top
=
S_char.base;
}
void
push_num(double
n)//数字进栈
{
*
++S_num.top
=
n;
}
void
push_char(char
c)//运算符号进栈
{
*
++S_char.top
=
c;
}
double
pop_num()//数字出栈
{
double
m
=
*S_num.top;
S_num.top--;
return
m;
}
char
pop_char()//运算符号出栈
{
char
cc
=
*S_char.top;
S_char.top--;
return
cc;
}
char
get_top_char()//得到运算符号的栈中最顶端的运算符号
{
return
*S_char.top;
}
double
operate(double
y,
char
c,
double
x)//
对两个数计算
(
含是双目运算符
:

*,
/
等等
)
{
double
r;
if(c
==
'-')
r
=
x
-
y;
else
if(c
==
'+')
r
=
x
+
y;
else
if(c
==
'/'
&&
y
!=
0)
r
=
x
/
y;
else
if(c
==
'*')
r
=
x
*
y;
else
if(c
==
'^')
{
r
=
1;
for(int
i
=
1;
i
<=
y;
i++)
r
*=
x;
}
else
if(c
==
'%')
{
int
r0
=
(int)x
%
(int)y;
r
=
double(r0);
}
return
r;
}
double
operate_one(double
one,
char
cc)//
对一个数运算
(
含单目运算符
:

log(L),
sin(S)
等等
)
{
double
r;
if(cc
==
'Q')
r
=
sqrt(one);
else
if(cc
==
'C')
r
=
cos(one);
else
if(cc
==
'S')
r
=
sin(one);
else
if(cc
==
'T')
r
=
tan(one);
else
if(cc
==
'c')
i++;
}
i++;
}
if(ge
>=
3)
return
0;
else
return
1;
}
void
output(double
result)//
打出结果
{
printf("
所得结果是
:
");
cout<<result<<endl;
}
void
check()//
检查表达式是否合法
{
void
introce();
char
cc;//
决定计算器按哪种功能进行计算
double
result;//
结果
void
input();//
定义
if(
check_kuohao()
&&
check_char()
)//
看是否合法
,
合法则计算
{
result
=
compute();
output(result);
cout<<"
输入一个字符
'M'

'D'

'F',
决定是否继续
:
"<<endl;
while(cin>>cc)
{
if(cc
==
'M')
{
system("cls");
introce();
printf("
您上次所得结果为
:
");
cout<<result<<endl;
cout<<"
在上次计算结果的基础上
,
请继续输入想计算的表达式
"<<endl;
dai_result
=
result;
biao
=
1;
input();//
输入表达式
break;
}
else
if(cc
==
'D')
{
system("cls");
introce();
cout<<"
计算器已清零
,
请输入您所要计算的表达式
"<<endl;
input();//
输入表达式
break;
}
else
if(cc
==
'F')
{
system("cls");
cout<<"
计算器关闭
,
谢谢使用
!"<<endl;
break;
}
else
{
cout<<"
所输入字符无效
,
请输入一个字符
'M'

'D'

'F'!"<<endl;
continue;
}
}
}
else//
不合法,分两种不合法
{
if(check_kuohao()
==
0
&&
check_char()
==
1)
{
cout<<"
您所输入的表达式括号不匹配
,
请重新输入
:"<<endl;
input();//
输入表达式
}
else
{
cout<<"
您所输入的表达式不合法
,
请重新输入
:"<<endl;
input();//
输入表达式
}
}
}
void
tackle_fuhao()//
处理负号
{
node
*root,
*head,
*p,
*q,
*p1;
root
=
head
=
new
node;
head->next
=
NULL;
int
i;
for(i
=
0;
line[i]
!=
'\0';
i++)//
建立链表
{
p
=
new
node;
p->data
=
line[i];
p->next
=
head->next;
head->next
=
p;
head
=
p;
}
//
delete
p;
q
=
(node*)malloc(sizeof(node));
head
=
root;
if(root->next->data
==
'+'
||
root->next->data
==
'-')//
处理第一个字符
{
p
=
new
node;
p->data
=
'0';
p->next
=
head->next;
head->next
=
p;
}
if(root->next
!=
NULL)
{
for(q
=
root->next;
q;
q
=
q->next)
{
if(q->data
==
'('
&&
(q->next->data
==
'-'
||
q->next->data
==
'+'))
{
p
=
new
node;
p->data
=
'0';
p->next
=
q->next;
q->next
=
p;
}
}
}
//
delete
q;
p1
=
new
node;
int
qi
=
-1;
for(p1
=
root->next;
p1;
p1
=
p1->next)
{
line[++qi]
=
p1->data;
}
line[++qi]
=
'\0';
}
void
input()//
输入
{
cin>>line;
if(biao
==
0)
tackle_fuhao();//
处理负号
check();//
检查表达式是否合法
}
void
introce()//
对计算器的符号功能的简要介绍
{
cout<<"
计算器简要介绍
"<<endl;
cout<<"C(cos)
S(sin)
T(tan)
a(arccos)
c(arcsin)
"<<endl;
cout<<"7
8
9
/
on
t(arctan)
"<<endl;
cout<<"4
5
6
*
%
L(log)"<<endl;
cout<<"1
2
3
-
M(M+)
Q(sqrt)
"<<endl;
cout<<"0
.
+
^(
乘方
)
F(off)
Enter(=)
"<<endl;
cout<<"
对于对数输入
L2_5
表示以
2
为底
5
的对数
"<<endl;
cout<<"M(
在前面结果的基础上继续计算,
如:
上次结果为
10

现输入
+10.5*2)"<<endl;
cout<<"D(
清零并继续输入
)"<<endl;
cout<<"F(
计算机关闭
)"<<endl;
cout<<"
输入
P
就代表输入圆周率
,
输入
E
代表输入自然对数
"<<endl<<endl;
}
void
print()
{
system("color
2");
cout<<"
欢迎使用本计算器
"<<endl;
cout<<"
输入一个字符串
on,
计算器开始启动
"<<endl;
}
void
if_start()//
是否启动计算器
{
string
start;
print();
while(cin>>start)
{
if(start
!=
"on")
{
cout<<"
您所输入的字符无效
,
请按照介绍的继续输入
:"<<endl;
continue;
}
else
break;
}
if(start
==
"on")
{
system("color
5");//
颜色的处理
system("cls");//
刷屏
}
introce();//
对计算器的简要介绍
cout<<"
现在
,
请输入您所要计算的表达式
"<<endl;
input();//
输入所要计算的表达式
}
int
main()
{
if_start();//
调用是否启动计算器函数
return
0;
}
r
=
acos(one);
else
if(cc
==
's')
r
=
asin(one);
else
if(cc
==
't')
r
=
atan(one);

热点内容
ubuntupython3安装 发布:2025-02-14 00:14:45 浏览:661
和平精英怎么更新比较快安卓 发布:2025-02-14 00:14:35 浏览:974
怎么改密码锁 发布:2025-02-13 23:47:39 浏览:852
androidbitmap获取大小 发布:2025-02-13 23:47:38 浏览:559
怎么把升级鸿蒙系统变回安卓 发布:2025-02-13 23:36:07 浏览:595
偶校验c语言 发布:2025-02-13 23:22:52 浏览:937
芒果如何提取离线缓存视频 发布:2025-02-13 23:16:12 浏览:793
王者荣耀微信区安卓哪里分低 发布:2025-02-13 23:14:10 浏览:658
安装linuxvmwaretools 发布:2025-02-13 22:56:02 浏览:8
浪潮服务器如何引导系统安装光盘 发布:2025-02-13 22:56:02 浏览:112