当前位置:网站首页>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
边栏推荐
- How to reduce the resolution of only 3D camera but not UI camera
- Floating point data type in C language (did you learn to waste it)
- @DS('slave') 多数据源兼容事务问题解决方案
- How many ways can multithread run in sequence?
- Qt development tips
- Factory mode and constructor mode
- C# 读取ini文件、键值对操作
- [leetcode] sticker spelling (dynamic planning)
- Simple data analysis using Weka and excel
- How to perform batch operations in core data
猜你喜欢

Copy excel row to specified row

Redis-Redis在Jedis中的使用

MITK create module

How to reduce the resolution of only 3D camera but not UI camera

爆肝整理JVM十大模块知识点总结,不信你还不懂

Getting started with scottplot tutorial: getting and displaying values at the mouse

Installing MySQL on Linux

数字化转型安全问题频发,山石网科助力数字政府建设

十、时间戳

The method of implementing simple student achievement management system with C language
随机推荐
爆肝整理JVM十大模块知识点总结,不信你还不懂
树莓派基础 | 总结记录树莓派学习过程中的一些操作
Factory mode and constructor mode
BGP experiment
9、 Uni popup usage popup effect at the bottom of the drop-down box
Analysis of thrift serialization protocol
在 SwiftUI 视图中打开 URL 的若干方法
文件批量重命名工具Bulk Rename Utility
Several methods of opening URL in swiftui view
String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
VTK notes - picker picker summary
Namespace conflict problem
The second pre class exercise
How to use the C language library function getchar ()
Getting started with scottplot tutorial: getting and displaying values at the mouse
Cv:: mat conversion to qimage error
SwiftUI 4.0 的全新导航系统
八、picker用法 下拉框选择效果
Ability to add class @published for custom attribute wrapper types
Creating, deleting and viewing Anaconda virtual environment