导航:首页 > 源码编译 > c语言怎样编译简单计算器

c语言怎样编译简单计算器

发布时间:2022-12-12 05:50:08

A. C语言编写简易计算器程序

C语言编写计算器

B. 用简单c语言编写计算器

#include"stdio.h"
/*预处理命令*/
void
main()
/*主函数*/
{
double
a,b;
/*双精度实型变量说明*/
char
c,d;
/*变量说明*/
do
/*循环体*/
{
printf("input
a
(-*/)b\n");
/*输入提示*/
scanf("%lf%c%lf",&a,&c,&b);
/*输入算术表达式*/
if(c=='
')
/*判断
*/
printf("=%0.2f",a
b);
/*输出a
b的值*/
else
if(c=='-')
/*判断-*/
printf("=%0.2f",a-b);
/*输出a-b的值*/
else
if(c=='*')
/*判断**/
printf("=%0.2f",a*b);
/*输出a*b的值*/
else
if(c=='/')
/*判断/*/
printf("=%0.3f",a/b);
/*输出a/b*/
else
/*不满足以上条件*/
printf("error");
/*输出错误*/
printf("\n\ninput\n");
/*输入\n*/
scanf("%c",&d);
/*输入符号给d*/
}
/*循环体结束*/
while(d=='\n');
/*循环条件语句*/
}

C. 用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();
}

D. C语言编写简单的计算器

#
#include<stdio.h>
void main()
{
float a,b;
char d;
printf("请输入两个数a,b:");
scanf("%f,%f"&a,&b);
printf("请输入符号d");
scanf("%c",d);
switch(d)
{
case'+':printf("%f\n,a+b);break;
case'-':printf("%f\n,a-b);break;
case'*':printf("%f\n,a*b);break;
case'/':printf("%f\n,a/b);break;
default:printf("input error\n");
}
}

E. 如何用C程序编写一个计算器

F. 怎样用C语言编写一个简单的可以进行加减乘除运算混合运算的计算器

用C语言编写一个简单的可以进行加减乘除运算混合运算的计算器的方法:

1、打开visual C++ 6.0-文件-新建-文件-C++ Source File;

G. 用c语言 (c++) 编写计算器程序

我们平时进行数学运算都是用计算器完成的,那么如何用C语言编写一个计算器呢?下面我给大家分享一下。

工具/材料

Dev C++

H. C语言编写一个简单的计算器

我给你写一个简单的计算器程序,你可以看一下。如果需要更多的功能,那么还要更复杂一些。不是一句话可以说明白的。要用到很多函数的调用,和函数的方法。
#include
"stdio.h"
void
main()
{
int
a,b,result;
char
m;
printf("请输入需要计算的数:\n");
scanf("%d
%d",&a,&b);
printf("请输入加、减、乘或除\n");
scanf("%c",&m);
if(m=="+")
//判断是否进行加法运算,以下同理
result=a+b;
else
if(m=="-")
result=a-b;
elsee
if(m=="*")
result=a*b;
else
if(m=="/")
result=a/b;
else
printf("您输入有误\n");
//如果输入的符号非加减乘或是除,报错
printf("计算结果为:%d\n",result);
//最后输出结果
}

I. 如何用C语言写一个简易计算器

#include<stdio.h>
int main()
{
double num1;
double num2;
double result;
char ch;
printf("Please enter express to caculate, 'q' to exit(eg. 1+3):");
while(scanf("%lf%c%lf",&num1,&ch,&num2) == 3)
{
switch(ch)
{
case '+':
{
result = num1 + num2;
break;
}
case '-':
{
result = num1 - num2;
break;
}
case '/':
{
if(num2 == 0)
printf("Error:div/0\n");
else
result = num1 / num2;
break;
}
case '*':
{
result = num1 * num2;
break;
}
}
printf("%g%c%g=%g\n",num1,ch,num2,result);
printf("Please enter express to caculate, 'q' to exit(eg. 1+3):");
}
return 0;
}

阅读全文

与c语言怎样编译简单计算器相关的资料

热点内容
礼记正义pdf 浏览:984
CorePDF 浏览:731
python多文件调用 浏览:327
linux如何用python 浏览:186
超易学的python 浏览:159
控制面板命令行 浏览:51
为什么空气难压缩是因为斥力吗 浏览:643
郭天祥单片机实验板 浏览:601
服务器有什么危害 浏览:258
饥荒怎么开新的独立服务器 浏览:753
文件夹变成了 浏览:560
linuxpython绿色版 浏览:431
怎么下载小爱同学音箱app 浏览:554
python占位符作用 浏览:76
javajdbcpdf 浏览:543
php网页模板下载 浏览:192
python试讲课pygame 浏览:409
安居客的文件夹名称 浏览:677
家里服务器如何玩 浏览:451
网站源码使用视频 浏览:748