码迷,mamicode.com
首页 > 其他好文 > 详细

循环语句的效率

时间:2018-08-02 12:26:41      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:cout   clu   复杂   namespace   提高   使用   c++   NPU   iostream   

循环语句的效率

C++/C 循环语句中,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 int main(int argc, char** argv) {
 6     int a,b,c;
 7     int smallest;
 8     cout<<"a  b  c"<<endl;
 9     cin>>a>>b>>c;
10     if (a<=b)    //外层条件语句
11     {
12         if (a<=c)    //内层条件语句
13            smallest=a;
14         else
15            smallest=c;
16     }
17     else
18     {
19        if (b<=c)    //内层条件语句
20            smallest=b;
21        else
22            smallest=c;
23     }
24     cout<<"Smallest="<<smallest<<endl;
25     return 0;
26 }

 

循环语句的效率

标签:cout   clu   复杂   namespace   提高   使用   c++   NPU   iostream   

原文地址:https://www.cnblogs.com/borter/p/9406243.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!