当前位置:网站首页>5、 C language judgment statement
5、 C language judgment statement
2022-07-28 14:53:00 【Rock magnon】
List of articles
1、C Judge
- Be careful : Required when the condition is true , The statement executed when the condition is false is optional
- Equivalence relation :
- true== Nonzero == Non empty
- false==null== zero
1. if,else if, else sentence
- if Statement can be followed by else if,else sentence
- else Statements must be placed at the end
- once else if Statement matching succeeded , other else if Statement and else Statement will not be executed
- Code implementation :
#include<stdio.h> #include<stdlib.h> int a = 10; int b = 20; int c = 30; int main(){ //if sentence if(a <= 10){ printf("a Less than or equal to 10\n"); } printf("a The value of is :%d\n",a); //if else sentence if(b == 15){ printf("b be equal to 15"); } else{ printf("b It's not equal to 15\n"); } //if else if else sentence if(c > 30){ printf("C Greater than 30"); } else if(c < 30){ printf("c Less than 30"); } else{ printf("c be equal to 30"); } } - Running results :
a Less than or equal to 10 a The value of is :10 b It's not equal to 15 c be equal to 30
2.switch sentence
- The rules :
- expression Must be constant , An integer or enumeration type
- When one case When the statement is executed , Subsequent statements will be executed , Until I met break sentence , Jump out of switch sentence
- default Statements must be placed at the end , Execute when none of the above statements match
- Format :
switch(expression){ case 1: Code block ; break; case 2: Code block ; break; default: Code block ; break;// Can not add } - Code implementation :
#include<stdio.h> #include<stdlib.h> int a = 10; int b = 10; int main(){ switch (a) { case 10: printf("a The value of is 10\n"); //switch Statement nesting switch (b) { case 100: printf("b The value of is 100\n"); break; default: printf("b The value is not 100\n"); break; } break; case 20: printf("a The value of is 20\n"); break; default: printf("a The value is not 10, Neither 20\n"); break;// Can not add } } - Running results :
a The value of is 10 b The value is not 100
3. Ternary operator
- Format :condition ?block1 : block2
- Operation process : When condition To true , function block1, Otherwise run block2
- Code implementation :
#include<stdio.h> #include<stdlib.h> int main(){ int num; printf(" Please enter a number :\n"); scanf("%d",&num); (num%2 == 0) ? printf(" even numbers \n") : printf(" Odd number \n"); return 0; } - Running results :
./test1 Please enter a number : 2 even numbers
边栏推荐
- UI开发中所遇到的各种坑
- Reptile: from introduction to imprisonment (I) -- Concept
- 十、时间戳
- Force deduction solution summary 1331 array sequence number conversion
- Third class exercise
- FormData对象的使用, var formdata=new FormData()
- Simple data analysis using Weka and excel
- 58子站安居,经纪人营销管理平台登录接口加密逆向
- Qt development tips
- Brief introduction and use of mqtt entry level
猜你喜欢

基于 MinIO 对象存储保障 Rancher 数据

Raspberry pie foundation | summarize and record some operations in the learning process of raspberry pie

2022 melting welding and thermal cutting examination questions and online simulation examination

Copy excel row to specified row
Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新

Creating, deleting and viewing Anaconda virtual environment

8、 Picker usage drop-down box selection effect

@Solution to DS ('slave') multi data source compatible transaction problem

ScottPlot入门教程:获取和显示鼠标处的数值

On July 29, apachecon | apachepulsar's exploration and practice in vivo will be broadcast soon
随机推荐
Digital transformation security issues occur frequently, and Shanshi Netcom helps build a digital government
Factory mode and constructor mode
基于 MinIO 对象存储保障 Rancher 数据
Swiftui layout - size (bottom)
7月29日 ApacheCon|Apache Pulsar 在 vivo 的探索与实践 即将开播
@DS('slave') 多数据源兼容事务问题解决方案
2022 high altitude installation, maintenance, removal of examination question bank and online simulated examination
Animation mechanism of swiftui
C语言实现简单学生成绩管理系统的方法
C language related programming exercises
It's so hot that solar power can't take off? Hello, head
Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance
linux安装redis
Hand in hand from 0 to a "Nuggets special attention" Google plug-in, 5000 words detailed vue3 responsive principle, the advantages, disadvantages and choices of several cache read-write schemes, flyin
Node file operation
Excel VBA 免密查看VBE加密代码
Create a table under swiftui with table
Raspberry pie foundation | summarize and record some operations in the learning process of raspberry pie
[leetcode] sticker spelling (dynamic planning)
468 product planning and promotion plan (150 copies)