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

热点内容
sqlintstring 发布:2025-10-19 19:54:02 浏览:414
sql2008企业管理器 发布:2025-10-19 19:43:51 浏览:435
centos8如何配置nfs 发布:2025-10-19 19:29:51 浏览:535
脚本预约 发布:2025-10-19 19:03:59 浏览:122
android多图上传 发布:2025-10-19 19:03:59 浏览:635
linux开通ftp 发布:2025-10-19 18:55:13 浏览:325
软件编程技术培训机构 发布:2025-10-19 18:13:32 浏览:865
c语言怎么赋值 发布:2025-10-19 18:12:40 浏览:536
ftp服务器监听IP地址 发布:2025-10-19 18:02:56 浏览:665
wordpress上传限制 发布:2025-10-19 17:58:55 浏览:955