循环语句的效率

循环语句的效率

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 }
原文地址:https://www.cnblogs.com/borter/p/9406243.html