当前位置:网站首页>switch实现表达式计算
switch实现表达式计算
2022-07-23 05:44:00 【xiq1212】
编写程序实现功能:
要求:
读入两个整数(data1和data2)和一个运算符(op),计算表达式data1 op data2 的值,其中op可以为+、-、*、/四个符号中的任一种(用switch语句实现)。
本题需要稍微留意的就是除法部分,整除取整,不好好搞定就容易得不到正确的运算结果。
s=(float)a/b;
2.完整版代码
#include <stdio.h>
int main(int argc, const char *argv[])
{
int a,b;
float s;
char c;
printf("请输入数字及字符:\n");
scanf("%d %d %c",&a,&b,&c);
switch(c)
{
case '+':
printf("运算结果为:%d\n",a+b);
break;
case '-':
printf("运算结果为:%d\n",a-b);
break;
case '*':
printf("运算结果为:%d\n",a*b);
break;
default :
s=(float)a/b;
printf("运算结果为:%f\n",s);
break;
}
return 0;
}
3.运行结果
请输入数字及字符:
12 23 +
运算结果为:35
边栏推荐
- 深度卷积生成对抗网络
- 【AUTOSAR COM 3.信号的收发流程TX/RX】
- Interpretation of the paper: DNA enhancer sequence recognition transformer structure based on Bert and two-dimensional convolutional neural network
- Interpretation of the paper: "deep-4mcw2v: sequence based predictor for identifying N4 methylcytosine (4mc) sites in E. coli"
- 钢结构基本原理复习
- 论文解读:《提高N7-甲基鸟苷(m7G)位点预测性能的迭代特征表示方法》
- 时间序列的数据分析(二):数据趋势的计算
- Solution to schema verification failure in saving substantive examination request
- Gartner research: how is China's digital development compared with the world level? Can high-performance computing dominate?
- Using pycaret for data mining: association rule mining
猜你喜欢
![[talent column] can't you use Apache dolphin scheduler? It takes a month to write the most comprehensive introductory teaching [2]](/img/34/abc6ef91d0b735f713f76da5a4b537.png)
[talent column] can't you use Apache dolphin scheduler? It takes a month to write the most comprehensive introductory teaching [2]

Hardware knowledge 1 -- Schematic diagram and interface type (based on Baiwen hardware operation Daquan video tutorial)

钢结构基本原理复习

利用google or-tools 求解逻辑难题:斑马问题

Interpretation of the paper: attention based multi label neural network for comprehensive prediction and interpretation of 12 widely existing RNA modifications

How to build a liquid cooling data center is supported by blue ocean brain liquid cooling technology

ARM架构与编程4--串口(基于百问网ARM架构与编程教程视频)

2021 TOP10 development trend of information science. Deep learning? Convolutional neural network?

Using or tools to solve the path planning problem with capacity constraints (CVRP)

编码器的一点理解
随机推荐
钢结构基本原理全面详细总结
怎么建立数据分析思维
数据分析(一)
论文解读:《开发一种基于多层深度学习的预测模型来鉴定DNA N4-甲基胞嘧啶修饰》
利用pycaret:低代码,自动化机器学习框架解决回归问题
What technologies are used in pharmaceutical research and development in the field of life sciences? Cryoelectron microscope? Molecular simulation? IND?
[talent column] can't you use Apache dolphin scheduler? It takes a month to write the most comprehensive introductory teaching [2]
Green data center: comprehensive analysis of air-cooled GPU server and water-cooled GPU server
【Autosar DEM 四.Event Memory】
利用google or-tools 求解数独难题
高分子物理名词解释
Interpretation of the paper: iterative feature representation method to improve the prediction performance of N7 methylguanosine (m7G) sites
利用or-tools来求解路径规划问题(VRP)
【AUTOSAR DCM 1.模块简介(DSL,DSD,DSP)】
Interpretation of the paper: develop and verify the deep learning system to classify the etiology of macular hole and predict the anatomical results
Data analysis of time series (I): main components
预处理指令#define,你真的懂了吗?
Using pycaret: low code, automated machine learning framework to solve classification problems
单片机学习笔记4--GPIO(基于百问网STM32F103系列教程)
Integrate all lvgl controls into one project (lvgl6.0 version)