网站首页 > 文章中心 > 其它

MySQL里乘法怎么算

作者:小编 更新时间:2023-10-20 14:29:41 浏览量:235人看过

c语言编写计算器程序

C语言编写计算器

然后需要检测输入是否是正确的,检查是不是+ - * / %,今天这一节要用到switch函数,用来看operation变量是否别传入了正确的值.

switch(operation)

{

case '+':

printf........

}

具体的运算我们只需要再case之后的printf语句中设定和输出就可以了.

使用c语言编程,用函数实现一个计算器,在主函数中调用函数,包括加减乘除,乘方,绝对值和sin函数.

#includestdio.h

#includestdlib.h

double jia(double a,double b)

return a+b;

double jian(double a,double b)

return a-b;

double cheng(double a,double b)

return a*b;

double chu(double a,double b)

return a/b;

double juedui(double a)

return a0 ? a : -a;

double chengfang(double a,double b)

return pow(a,b);

double sinx(double a)

return sin(a);

int main()

int m;

double a,b;

while(1)

printf("请输入第一个操作数:");

scanf("%lf",a);

scanf("%d",m);

printf("请输入第二个操作数:");

scanf("%lf",b);

switch(m)

case 0:

exit(0);

break;

case 1:

printf("%lf+%lf=%lf\n",a,b,jia(a,b));

printf("%lf-%lf=%lf\n",a,b,jian(a,b));

printf("%lf*%lf=%lf\n",a,b,cheng(a,b));

if(0.0==b)

printf("除数不能为0.\n");

else

printf("%lf/%lf=%lf\n",a,b,chu(a,b));

printf("|%lf|=%lf\n",a,juedui(a));

printf("%lf的%lf方=%lf\n",a,b,chengfang(a,b));

printf("sin(%lf)=%lf\n",a,sinx(a));

default:

printf("无法处理的命令.\n");

system("PAUSE");

return EXIT_SUCCESS;

用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);

*value=-1;

int empty(link stack)

if(stack==NULL)

return 1;

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;

default: return 0;

void main()

int position=0;

int op=0;

int operand1=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);

operator=pop(operator,op);

operator=push(operator,expression[position]);

position++;

while(!empty(operator))

operand=pop(operand,evaluate);

printf("The expression [%s] result is '%d' ",expression,evaluate);

getch();

用C语言做一个计算器,能实现加减乘除混合运算

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

#includestdio.h /*函数头:输入输出头文件*/

void main()/*空类型:主函数*/

int a,b,d; /*定义变量的数据类型为整型*/

char c;/*定义变量的数据类型为字符型*/

scanf("%d%c%d",a,c,b);/*输入四则运算式*/

switch(c) /*判断运算符号*/

case'+':d=a+b;break;/*进行加法运算*/

case'-':d=a-b;break;/*进行减法运算*/

case'*':d=a*b;break;/*进行乘法运算*/

case'/':d=a/b;break; /*进行除法运算*/

printf("%d%c%d=%d\n",a,c,b,d);/*输出结果*/

完整的源代码:

int a,b,d;/*定义变量的数据类型为整型*/

switch(c)/*判断运算符号*/

case'/':d=a/b;break;/*进行除法运算*/

C语言函数做计算器的问题

在jisuanqi()已经输出,在main()又一次输出jisuanqi()的返回值a+b.可以修改如下:

#include

"stdio.h"

int

jisuanqi(int

a,char

c,

b)

switch(c)

case

'+':

printf("%d\n",a+b);

'-':

printf("%d\n",a-b);

'*':

printf("%d\n",a*b);

'/':

printf("%d\n",a/b);

return

0;

main(int

argc,

char*

argv[])

a,b;

char

c;

scanf("%d

%c

%d",a,c,b);

jisuanqi(a,c,b);

C语言编写计算器

总算看懂了,一个只能两个数相加减乘除的计算器何必写的那么复杂,竟然还用了六个函数,下面我写一个功能一样的,更精简方便的,只要一个函数.

/*

Note:Your

choice

is

C

IDE

*/

/*一个具有两个数加减乘除功能的计算器*/

void

main()

iFirNum,iSecNum,iResult;

ch,ch1;

printf("请输入表达式如

然后按回车键:");

scanf("%d%c%d%c",iFirNum,ch,iSecNum,ch1);

switch(ch)

iResult=iFirNum+iSecNum;

printf("%d+%d=%d\n",iFirNum,iSecNum,iResult);

iResult=iFirNum-iSecNum;

printf("%d-%d=%d\n",iFirNum,iSecNum,iResult);

iResult=iFirNum*iSecNum;

printf("%d*%d=%d\n",iFirNum,iSecNum,iResult);

iResult=iFirNum/iSecNum;

printf("%d/%d=%d\n",iFirNum,iSecNum,iResult);

printf("输入表达式错误或该计算器不具备

%ch

功能\n",ch);

以上就是土嘎嘎小编为大家整理的MySQL里乘法怎么算相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章