当前位置:网站首页>C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea

C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea

2022-07-05 09:16:00 Robbin_ mi

#include <stdio.h>
int main()
{
	int a[3][5]={ 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5};
	int j,i,b,z,num=0;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 5; j++) {
			printf("%2d", a[i][j]);
			num++;
		}
		if (num % 5 == 0) printf("\n");
	}
	printf("--------------------\n");
	int a[3][5]={ 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5};
	int j,i,b,z,num=0;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 2; j++) {
			b = a[i][0];
			for (z = 1; z < 5; z++) {
				a[i][z - 1] = a[i][z];
			}
			a[i][4] = b;
		}
	}
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 5; j++) {
			printf("%2d", a[i][j]);
			num++;
		}
		if (num % 5 == 0) printf("\n");
	}
}

原网站

版权声明
本文为[Robbin_ mi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050914557657.html