当前位置:网站首页>First knowledge of C language ~ branch statements
First knowledge of C language ~ branch statements
2022-04-23 02:42:00 【^O ^ play programming】
Catalog
The branch family of love choice
A little brother who has found another way switch
Preface
Starting today , I will continue to share with you what I have learned C History , What I'm sharing with you today is the branch statement .
C Language sentences
C Sentences can be divided into the following five categories : 1. Expression statement
2. Function call statements
3. Control statement
4. Compound statement
5. Empty statement
What I want to share today is : Control statement
So what is a control statement ?
In short, it is the process of controlling program execution , stay C There are three families in language .
Today, let's introduce : The branch family of love choice , In the following, we will introduce the circulation family of one tendon and the steering family of turning .
The branch family of love choice
There are two members in this family , Omnipotent brother if And the little brother who found another way switch. The members of this family have a common characteristic is love " choice ", Come on, let's go into this interesting family !
Omnipotent brother if
if Big brother's cognition : expression (" really " Just get up ," false " Just bye )
0 Said the false , Not 0 Said really .
Illustrate with examples :
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int a = 0; printf(" Selectivity C Language attitude :\n"); scanf("%d", &a); if (0 != a) { printf(" Study hard C Language \n"); } else { printf(" Don't study hard C Language \n"); } return 0; }Print :
know if Brother's attention :1 if I love the one closest to him else( Match ).
2 if To execute multiple statements later, use {}.
A little brother who has found another way switch
about switch We should pay special attention to , His judgment condition is Shaping expression .
Illustrate with examples :
#include<stdio.h> int main() { int day = 0; scanf("%d", &day); switch (day) { case 1: printf(" Monday \n"); break; case 2: printf(" Tuesday \n"); break; case 3: printf(" Wednesday \n"); break; case 4: printf(" Thursday \n"); break; case 5: printf(" Friday \n"); break; case 6: printf(" Saturday \n"); break; case 7: printf(" Sunday \n"); break; default: printf(" Wrong choice \n"); break; } return 0; }Print :
In order to change
1. Input 1-5, The output is “weekday”;
2. Input 6-7, Output “weekend”
How can we write :
#include <stdio.h> //switch Code demonstration int main() { int day = 0; scanf("%d", &day); switch (day) { case 1: case 2: case 3: case 4: case 5: printf("weekday\n"); break; case 6: case 7: printf("weekend\n"); break; } return 0; }switch Summary of :1 It means to jump out of this cycle break.
2 When switch The value of the expression is the same as all case If the values of the tags do not match, the statement will be skipped .
3 default(/dɪ'fɔːlt/) Can appear in switch Anywhere in , And only 1 strip , do Use is when the value in the expression and csae When it doesn't match, start from default The statement following the clause will execute .
4 We usually work in every case Add a... After each statement break Develop good programming habits .
版权声明
本文为[^O ^ play programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220748162379.html
边栏推荐
- IAR embedded development stm32f103c8t6 Lighting LED
- day18--栈队列
- Rhcsa day 4 operation
- Efficient music format conversion tool Music Converter Pro
- Intelligent agricultural management model
- Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
- C language 171 Number of recent palindromes
- OCR识别PDF文件
- [unity3d] rolling barrage effect in live broadcasting room
- JZ22 链表中倒数最后k个结点
猜你喜欢

Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad

国产轻量级看板式Scrum敏捷项目管理工具

Flink learning (XI) watermark
![Parental delegation model [understanding]](/img/ba/07e280a2634018e0d6b56c05dd3bc0.png)
Parental delegation model [understanding]

十六、异常检测

How to recognize products from the perspective of Dialectics

Global, exclusive, local Routing Guard

The usage and difference of * and & in C language and the meaning of keywords static and volatile

ROP Emporium x86_ 64 7 ~ 8 questions

Modify the content of MySQL + PHP drop-down box
随机推荐
5W of knowledge points
谷雨
JZ76 删除链表中重复的结点
Target narak
C语言 171. 最近回文数
[suggestion collection] hematemesis sorting out golang interview dry goods 21 questions - hanging interviewer-1
下载正版Origin Pro 2022 教程 及 如何 激 活
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
定了,今日起,本号粉丝可免费参与网易数据分析培训营!
Servlet template engine usage example
The usage and difference of * and & in C language and the meaning of keywords static and volatile
Modify the content of MySQL + PHP drop-down box
First day of rhcsa
【unity3D】直播间滚动式弹幕效果
Web learning record (medium)
php+mysql對下拉框搜索的內容修改
IAR embedded development stm32f103c8t6 Lighting LED
The second day of learning rhcsa
Use of go language web Middleware
Machine learning (Zhou Zhihua) Chapter 14 probability graph model




