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 ;
}
}
}
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++基础编程练习18
- 黑马程序员-DOM编程基础知识练习程序(11-17)
- LinuxC/C++编程基础(11) 基于深度优先搜索查找迷宫路线
- c++基础编程练习17
- C++基础编程练习14
- c++基础编程练习13
- C++ 编程练习3
- c++ primer plus(第6版)中文版 第五章编程练习答案
- C++基础编程----1.1预备知识
- C++primer plus第六版课后编程练习答案2.6
- Java 编程思想(第4版)学习笔记(迭代器 Iterator ListIterator 第11章练习11)
- C语言 第三章 基础编程测试与练习
- LinuxC/C++编程基础(6) 堆排序的实现
- C++primer plus第六版课后编程练习答案4.7
- C++ Primer Plus课后编程练习——第七章 函数-C++的编程模块(部分)
- C++ primer plus第六版课后编程练习答案:6.7
- C++ Primer Plus 学习笔记 第四章 04编程练习
- C++和Matlab最常用的编程技能,实现复杂算法的基础
- C++primer plus第六版课后编程练习答案6.6
- 编程基础-----c++与c调用so文件