当前位置:网站首页>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
边栏推荐
- Fashion MNIST dataset classification training
- Suggestion: block reference sorting is in the order of keywords
- Intelligent agricultural management model
- Classification and regression tree of machine learning
- Go语言web中间件的使用
- MySQL JDBC programming
- 基于Scrum进行创新和管理
- Push data from onenet cloud platform to database
- MySQL JDBC编程
- 解决win7 中powershell挖矿占用CPU100%
猜你喜欢
Intelligent agricultural management model
Fashion MNIST 数据集分类训练
RT_ Thread ask and answer
【Hcip】OSPF常用的6种LSA详解
[untitled]
[wechat applet] set the bottom menu (tabbar) for the applet
C语言 171. 最近回文数
[XJTU computer network security and management] Lecture 2 password technology
[unity3d] rolling barrage effect in live broadcasting room
Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
随机推荐
Water diversion into chengluo Valley p1514
So library dependency
A domestic image segmentation project is heavy and open source!
grain rain
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
leangoo脑图-共享式多人协作思维导图工具分享
Flink stream processing engine system learning (III)
JZ22 链表中倒数最后k个结点
MySQL复杂查询使用临时表/with as(类似表变量)
能做多大的单片机项目程序开发,就代表了你的敲代码的水平
[wechat applet] set the bottom menu (tabbar) for the applet
Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
[XJTU计算机网络安全与管理]第二讲 密码技术
Android 高阶面试必问:全局业务和项目的架构设计与重构
Step principle of logical regression in machine learning
WordPress calls the specified page content. 2 get_ children()
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
Probabilistic model of machine learning
[untitled]
在MySQL Workbench中执行外部的SQL脚本,报错