您的位置:首页 > 编程语言 > C语言/C++

c++基础编程练习11

2012-09-16 15:58 330 查看
/*

11: 第11题 下列程序定义了n×n的二维数组,并在主函数中自动赋值。

请编写函数 fun(int a[]
),

该函数的功能是:使数组左下半三角元素中的值全部置成0。

*/

#include <iostream>

using namespace std ;

const int n = 4 ;

const int m = 4 ;

void fun_right_down(int a[]
) ;

void fun_left_down(int a[]
) ;

void init_array(int a[]
) ;

void display_array(int a[]
) ;

int main(){

    int a

;

    init_array(a) ;

    display_array(a) ;

#if 1

    fun_left_down(a) ;

    display_array(a) ;

#endif

#if 0

    fun_right_down(a) ;

    display_array(a) ;

#endif

    getchar();

    return 0 ;

}

void init_array(int a[]
){

    for (int i=0; i<n; i++){

        for (int j=0; j<n; j++){

            a[i][j] = n;

        }

    }

}

void display_array(int a[]
){

    for (int i=0; i<n; i++){

        for (int j=0; j<n; j++){

        

            cout << a[i][j] << " " ;

        }

        cout << endl ;

    }

}

void fun_left_down(int a[]
){

    int i , j ;

    for (int i=1; i<n; i++){

        for (int j=0; j<i; j++){

            a[i][j] = 0 ;

        }

    }

}

void fun_right_down(int a[]
){

    int i,j ;

    for (i = n-1; i>0; i--){

        for (j=n-1; j>(n-i-1);j--){

             a[i][j] = 0 ;

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ 编程 fun