当前位置 博文首页 > Mints:【C++提高班】c++数组遍历比较相邻的数值

    Mints:【C++提高班】c++数组遍历比较相邻的数值

    作者:[db:作者] 时间:2021-07-02 15:41

    冒泡里遍历比较会用到,两种都可以,不过要注意范围。容易混淆。

    #include <iostream>
    
    using namespace std;
    
    int main() {
        int a[3] = {0, 1, 2};
        
        int i = 0, n = 3;
        
        for(i = 0 ; i < n - 1; i++){
            cout << a[i] <<" " << a[i+1]<< endl;
        }
        
        cout << "*****************************" << endl;
        
        for(i = 1; i < n ; i++){
            cout << a[i-1] << " " << a[i] << endl;  
        }
    }
    
    cs
    下一篇:没有了