当前位置:网站首页>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 ”.
边栏推荐
- MySQL - table creation and management
- 抖音实战~分享模块~复制短视频链接
- WebView load pdf
- Nftgamefi chain game system development detailed solution - chain game system development principle analysis
- Unity - URP get camera stack
- Introduction to single chip microcomputer one-on-one learning strategy, independent development program immediately after reading
- Good thing recommendation: mobile terminal development security tool
- Review of watermelon book (VII): Bayesian classifier (manual push + code demo)
- 710. random numbers in the blacklist
- 0基础学c语言(1)
猜你喜欢

On the origin of the dispute between the tradition and the future of database -- AWS series column

Tiktok practice ~ homepage video ~ pull-down refresh

Minimum spanning tree, shortest path, topology sorting, critical path

Unity——Mathf. Similarities and differences between atan and atan2

Boot的单元测试

On the escape of inequality value

Disruptor本地线程队列_使用transProcessor处理器和WorkPool两种方式进行消费对比---线程间通信工作笔记005

Introduction to single chip microcomputer one-on-one learning strategy, independent development program immediately after reading

黑客用机器学习发动攻击的九种方法

Dynamic planning 111
随机推荐
460million zongzi were sold in half a year. How big is the "imagination space" of time-honored brands?
Web resource preloading - production environment practice
郭明錤:苹果 AR / MR 头显是其有史以来设计最复杂的产品,将于 2023 年 1 月发布
Is it safe to open a securities account? Is there any danger
MySQL recharge
JS mobile terminal touch screen event
开户可以在网上开么?能安全吗?
威胁猎人必备的六个威胁追踪工具
BOM and DOM operations
Feitian +cipu body brings more imagination to the metauniverse
C# 练习。类列表加记录,显示记录和清空记录
关于不等式取值转义的思路
c语言简单的登录
MySQL中存储过程的详细详解
Summary of several common UML diagrams
Super VRT
关于Qt数据库开发的一些冷知识
swagger:如何生成漂亮的静态文档说明页
IK word breaker
Guomingyu: Apple's AR / MR head mounted display is the most complicated product in its history and will be released in January 2023