当前位置:首页 » 编程软件 » 编程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;
}

热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:515
微博数据库设计 发布:2025-07-05 15:30:55 浏览:19
linux485 发布:2025-07-05 14:38:28 浏览:299
php用的软件 发布:2025-07-05 14:06:22 浏览:750
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:425
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:686
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:233
java的开发流程 发布:2025-07-05 12:45:11 浏览:678
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:277
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:828