if、for、while、do 等语句自占一行
for 语句 if 一行 while Do
2023-09-14 09:12:04 时间
if、for、while、do 等语句自占一行,执行语句不得紧跟其后。不论 执行语句有多少都要加{}。这样可以防止书写失误。
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 //用函数原型声明要使用的函数 6 void show_array1(int*,int); 7 void show_array2(int a[],int); 8 void sort(int*,int); 9 10 int main(int argc, char** argv) { 11 12 //声明数组并初始化 13 int a[]={2,4,6,1,3,5}; 14 int b[3][3]={{2,4,6},{1,3,5},{0,1,2}}; 15 16 //显示数组的值 17 cout<<"show_array1(int*,int):"<<endl; 18 show_array1(a,6); 19 show_array1(&b[0][0],3*3); 20 21 //用sort1排序并显示 22 cout<<"sort(int*,int) and show_array1(int*,int): "<<endl; 23 sort(a,6); 24 show_array1(a,6); 25 sort(&b[0][0],3*3); 26 show_array1(&b[0][0],9); 27 28 //显示数组的值 29 cout<<"show_array2(int a[],int):"<<endl; 30 show_array2(a,6); 31 show_array2(&b[0][0],3*3); 32 return 0; 33 } 34 35 36 //显示数组,用指针当参数 37 void show_array1(int *p,int size) { 38 for(int i=0;i<size;i++) 39 cout<<*(p+i)<<" "; 40 cout<<endl; 41 } 42 43 //显示数组,用数组当参数 44 void show_array2(int a[],int size) { 45 for(int i=0;i<size;i++) 46 cout<<a[i]<<" "; 47 cout<<endl; 48 } 49 50 //对数组按从大到小顺序排序 51 void sort(int *p,int size) { 52 int t; 53 for (int i=0;i<size-1;i++) 54 for (int j=i+1;j<size;j++) 55 if (*(p+i)<=*(p+j)) 56 { 57 t=*(p+i); 58 *(p+i)=*(p+j); 59 *(p+j)=t; 60 } 61 }
相关文章
- [AWS] CloudFormation: create EC2 with SecurityGroupIds for custom VPC
- [Python] numpy fillna() for Dataframe
- 【JAVA】foreach语句 -- for(int I : nums){}
- [AWS] Route 53 for A/B Testing
- There is no source code available for the current location
- Is there dedicated DDIC structure generated for each CDS entity
- 【Educational Codeforces Round 81 (Rated for Div. 2) B】Infinite Prefixes
- 【codeforces 768B】Code For 1
- TeeChart Pro FOR delphi 年底稳定版
- Spire Office 7.7.2 for .NET | Spire.Office Enterprise
- Spire.Office for Java 8.2.0 强大之喜Xaspose
- Python语言学习:Python语言学习之逻辑控制语句(if语句&for语句&while语句&range语句&with语句)的简介、案例应用之详细攻略
- C++:C++编程语言学习之基本数据类型/流程控制(if else/switch/for/while循环语句)的简介、案例应用之详细攻略
- 【异常】Dbeaver配置JDBC连接ES时提示SQL错误:current license is non-compliant for [jdbc]
- RobotFrameWork - 11 - Selenium API - if分支语句与for循环
- JavaScript基础&实战(3)js中的流程控制语句、条件分支语句、for循环、while循环
- 使用generate...for语句简化代码
- python web py入门(38)- javascript的for循环语句
- Verilog | for语句的理解与使用
- 【异常】MySQL提示MysqlDataTruncation: Data truncation: Data too long for column ‘name‘ at row 1
- 论文阅读【ACM_2020】SimSwap: An Efficient Framework For High Fidelity Face Swapping
- 【C++要笑着学】内联函数 inline | auto关键字(C++11) | 范围for | 关键字 nullptr