当前位置:网站首页>0 basic C language (3)
0 basic C language (3)
2022-06-26 20:21:00 【the best b】
Judge
Now we want to make a code to calculate the time difference .
Enter two times , Enter hours and minutes for each time , Then output the difference between the two times .
We give 1 spot 40 and 2 spot 10 branch , Two hours
int hour1,minute1;
int hour2,minute2;
scanf("%d %d",&hour1,minute1);
scanf("%d %d",&hour2,minute2);
We want to c Input two times, but do you want to subtract directly to get the difference between the two times . If we subtract separately , Then the minutely minus result we get will be less than 0.
int hour1,minute1;
int hour2,minute2;
scanf("%d %d",&hour1,minute1);
scanf("%d %d",&hour2,minute2);
int ih=hour2-hour1;
int im=minute2-minute1;
if(im<0){
im=60+im;
ih--;
}
printf(" The time difference is %d Hours %d branch .\n",ih,im);
We set up one if Conditional statement if if If the conditions are met, it will proceed if The output of the statement in .
This is a simple judgment .
We give the relation of calculating two values , This is called relational operation
| Operator | significance |
|---|---|
| == | equal |
| != | It's not equal |
| > | d Greater than |
| >= | Greater than or equal to |
| < | Less than |
| <= | Less than or equal to |
| Column 1 | Column 2 |
All relational operators have a lower priority than arithmetic operations , But higher than the assignment operation .
To determine whether they are equal == and != The priority of is lower than others , Continuous relational operations are performed from left to right .
Next, we run the code of a change calculator
Want to make a change calculator , First, the user needs to do two operations 1. Enter the purchase amount ,2. Enter payment split face , The change computer performs corresponding actions according to these two values .
These are read into two inputs for calculation and judgment , Final output .
// initialization
int price=0;
int bill=0;
// Read in the amount and face value
printf(" Please enter the amount :");
scanf("%d",&price);
printf(" Please enter the face value :");
scanf("%d",&bill);
// Calculate the change
print(" I should call you :%d\n",bill-price);
In this code we add // Two slashes indicate a comment .
A comment that continues several lines , To write in the format of multi line comments , By a pair of characters "/“ Start , With ”/" end .
If the amount of the above code is greater than the face value , What should I do if the face value is not enough
We can use if Sentence to judge .
// initialization
int price=0;
int bill=0;
// Read in the amount and face value
printf(" Please enter the amount :");
scanf("%d",&price);
printf(" Please enter the face value :");
scanf("%d",&bill);
// Calculate the change
if(bill>=price){
printf(" I should call you :%d\n",bill-price);
}
printf(" You don't have enough money \n");
When if When the statement of is not true, it will output “ You don't have enough money ”.
边栏推荐
- Muke 8. Service fault tolerance Sentinel
- Kubernetes resource topology aware scheduling optimization
- C primer plus学习笔记 —— 3、字符的IO(输入/输出)
- Minimum spanning tree, shortest path, topology sorting, critical path
- MySQL - subquery usage
- Jz-062- the k-th node of binary search tree
- 0基础学c语言(2)
- Some cold knowledge about QT database development
- 抖音实战~分享模块~生成短视频二维码
- Invocation failed Unexpected end of file from server
猜你喜欢

论数据库的传统与未来之争之溯源溯本----AWS系列专栏

Pinda general permission system (day 1~day 2)

Detailed explanation of retrospective thinking

Good thing recommendation: mobile terminal development security tool

Unit test of boot
Detailed explanation of stored procedures in MySQL

Tiktok practice ~ sharing module ~ short video download (save to photo album)

Six necessary threat tracking tools for threat hunters

c语言99乘法表

数据库范式和主码的选择
随机推荐
710. 黑名单中的随机数
阿里云个人镜像仓库日常基本使用
Kubernetes 资源拓扑感知调度优化
Kubernetes resource topology aware scheduling optimization
swagger:如何生成漂亮的静态文档说明页
Is it safe to open a securities account? Is there any danger
710. random numbers in the blacklist
问题解决:虚拟机无法复制粘贴文件
C# 练习。类列表加记录,显示记录和清空记录
抖音实战~搜索页面~视频详情
MySQL中存储过程的详细详解
MongoDB实现创建删除数据库、创建删除表(集合)、数据增删改查
0基础学c语言(1)
JS mobile terminal touch screen event
The king of Internet of things protocol: mqtt
Dynamic planning 111
Disruptor本地线程队列_使用transProcessor处理器和WorkPool两种方式进行消费对比---线程间通信工作笔记005
Database SQL statement writing
Separate save file for debug symbols after strip
Résolution du problème: la machine virtuelle n'a pas pu copier et coller le fichier