当前位置:网站首页>C language: a simple calculator is implemented by using code many times
C language: a simple calculator is implemented by using code many times
2022-06-26 22:16:00 【Nianchi ichthyology programming】
#include <stdio.h>
int mul(int x , int y);
float div(float x , float y);
int yushu(int x , int y);
int add(int x , int y){
int z;
//printf(" Enter two integers :");
//scanf("%d%d",&x , &y);
z = x + y;
return z;
}
int sub(int x , int y){
int z;
z = x - y;
return z;
}
void Menu()
{
printf(" Welcome to the calculator \n");
printf(" \n");
printf("--------------------------- \n");
printf("1. Add 2. Subtraction \n3. Multiplication 4. division \n5. remainder 6. Back to main menu \n");
printf("--------------------------- \n");
printf(" \n");
}
int main()
{
char ch1 = 'y',ch2,a;
printf(" Please select 1-6:");
while(ch1 == 'y'||ch1 =='Y'){
Menu();
printf("== Please enter ==\n");
printf(" Please enter your choice :\n");
scanf("%c",&ch2);
getchar();
switch(ch2){
case '1':{
int a , b , c;
printf(" Enter two integers :");
scanf("%d%d",&a , &b);
c = add(a,b);
printf("%d + %d = %d \n", a , b , c);
break;
}
case '2':{
int a , b , c;
printf(" Enter two integers :");
scanf("%d%d",&a , &b);
c = sub(a,b);
printf("%d - %d = %d \n", a , b , c);
break;
}
case '3':{
int a , b , c;
printf(" Enter two integers :");
scanf("%d%d",&a , &b);
c = mul(a,b);
printf("%d * %d = %d \n", a , b , c);
break;
}
case '4':{
int a , b ;
float c;
printf(" Enter two integers :");
scanf("%d%d",&a , &b);
c = div(a,b);
printf("%d / %d = %g \n", a , b , c);
break;
}
case '5':{
int a , b , c;
printf(" Enter two integers :");
scanf("%d%d",&a , &b);
c = yushu(a,b);
printf("%d %% %d = %d \n", a , b , c);
break;
}
case '6':{
ch1 = 'n';
break;
}
default:{
printf(" Incorrect input , Please enter 0-9 Make a selection !");
break;
}
}
if(ch2 != '\0'){
printf(" Press any key to continue , Back to main menu \n");
a = getchar();
if(a != '\xA'){
getchar();
ch1 = 'n';
}
}
}
}
int mul(int x , int y){
int z;
z = x * y;
return z;
}
float div(float x , float y){
float z;
z = x / y;
return z;
}
int yushu(int x , int y){
int z;
z = x % y;
return z;
}
边栏推荐
- Leetcode (122) - the best time to buy and sell stocks II
- Is it safe for CICC fortune to open an account? I want to open an account to speculate in stocks.
- 网络爬虫终篇:向10万级网易云用户发送定向消息
- vulnhub之dc8
- 大龄程序员的一些出路
- JupyterLab 常用配置
- 美术向的Unity动画知识
- 简析攻防演练中蓝队的自查内容
- Common configuration of jupyterlab
- leetcode:1567. 乘积为正数的最长子数组长度【dp[i]表示以i结尾的最大长度】
猜你喜欢
![leetcode:152. Product maximum subarray [consider DP of two dimensions]](/img/c8/af6a4c969affd151a5214723dffb57.png)
leetcode:152. Product maximum subarray [consider DP of two dimensions]

leetcode:710. 黑名单中的随机数【映射思维】

Pass note 【 dynamic planning 】

leetcode:6107. 不同骰子序列的数目【dp六个状态 + dfs记忆化】

卷积神经网络(CNN)详解及TensorFlow2代码实现

MATLAB与Mysql数据库连接并数据交换(基于ODBC)

Unity: 脚本缺失 “The referenced script (Unknown) on this Behaviour is missing!“

Convolutional neural network (CNN) explanation and tensorflow2 code implementation

Raspberry pie preliminary use

Web crawler 2: crawl the user ID and home page address of Netease cloud music reviews
随机推荐
Application and Optimization Practice of 100 million level monthly live national karaoke feed service in Tencent cloud mongodb
CVPR 2022 - Interpretation of selected papers of meituan technical team
如何写好测试用例以及go单元测试工具testify简单介绍
Is there any risk in opening a securities registration account? Is it safe?
Yolov6: the fast and accurate target detection framework is open source
[mixed programming JNI] Part 6: operation of strings and arrays in native
矩阵求导及其链式法则
Vulnhub's DC8
nmap参数详解
Is this a bug? Whether the randomly filled letters can be closed
leetcode:152. 乘积最大子数组【考虑两个维度的dp】
Data governance does everything
Unity 设置Material、Shader的方法
VB. Net class library to obtain the color under the mouse in the screen (Advanced - 3)
简析攻防演练中蓝队的自查内容
Word chess based on heuristic search
简述unity的模型动画功能
Leetcode (763) -- dividing letter ranges
Convolutional neural network (CNN) explanation and tensorflow2 code implementation
Centos7 compiling and installing redis