当前位置:首页 » 编程软件 » 编程opt

编程opt

发布时间: 2023-08-29 00:57:29

❶ 用C语言编程实现一个简单的四则运算计算器

#include <stdio.h>

//函数,读数操作数
int getNextNum()
{
int ret;
scanf("%d",&ret);
return ret;
}

//函数,读运算符
char getOpt()
{
return getchar();
}

//函数,计算
int caculate(int op1 , int op2 ,char opt)
{
if(opt=='+')return op1+op2;
if(opt=='-')return op1-op2;
if(opt=='*')return op1*op2;
if(opt=='/')return op1/op2;
return 0;
}

int main()
{
int op1,op2;
char opt;
//计算结果放在第一个操作数
op1 = getNextNum();
while(1)
{
opt = getOpt();
if ( opt == '=' ) break;
op2 = getNextNum();
op1 = caculate(op1,op2,opt);
}
printf("%d\n",op1);
}
return 0;
}

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:588
制作脚本网站 发布:2025-10-20 08:17:34 浏览:884
python中的init方法 发布:2025-10-20 08:17:33 浏览:576
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:762
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:679
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1009
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:252
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:110
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:801
python股票数据获取 发布:2025-10-20 07:39:44 浏览:708