标签:
#include <stdio.h> int main( ) { int i,j; int a[5][4] = { {0,1}, {4,5}, {8,9}, {12,13}, {16,17} }; printf ("请输入10个整数:\n"); for (i=0;i<5;i++) { for (j=2;j<4;j++) { scanf ("%d", &a[i][j]); } } printf ("数组中的值为:\n"); for (i=0;i<5;i++) { for (j=0;j<4;j++) { printf ("%d\t", a[i][j]); } printf ("\n"); } printf ("现在将所有元素乘以3倍..."); for (i=0;i<5;i++) { for (j=0;j<4;j++) { a[i][j] *= 3; } } printf ("完成\n"); printf ("行序优先输出:\n"); for (i=0;i<5;i++) { for (j=0;j<4;j++) { printf ("%d\t", a[i][j]); } printf ("\n"); } printf ("列序优先输出:\n"); for (i=0;i<4;i++) { for (j=0;j<5;j++) { printf("%d\t", a[j][i]); } printf ("\n"); } printf ("倒着输出:\n"); for (i=4;i>=0;i--) { for (j=3;j>=0;j--) { printf ("%d\t", a[i][j]); } printf ("\n"); } printf ("数组中的偶数:\n"); for (i=0;i<5;i++) { for (j=0;j<4;j++) { if(0 == a[i][j]%2) { printf("a[%d][%d]=%d\n", i, j, a[i][j]); } } } printf ("\n"); printf ("行列下标之和为3的倍数的元素:\n"); for (i=0;i<5;i++) { for (j=0;j<4;j++) { if (0 == (i+j)%3) printf ("a[%d][%d]=%d\n", i, j, a[i][j]); } } printf ("\n"); return 0; }运行结果:
#include<stdio.h> int main() { int a[4][3]={{1,2,3}, {4,5,6}, {7,8,9}, {10,11,12}}; int b[4][3]={{10,20,30}, {40,50,60}, {70,80,90}, {100,110,120}}; int c[4][3]; int i=0,j=0; for (i=0;i<4;i++) { for (j=0;j<3;j++) { c[i][j] = a[i][j] + b[i][j]; printf ("%d\t", c[i][j]); } printf ("\n"); } return 0; }运行结果:
#include<stdio.h> int main() { int a[2][3]={{1,1,0}, {2,0,3}}; int b[3][4]={{0,2,3,1}, {1,0,2,2}, {2,1,1,1}}; int c[2][4]; int i=0, j=0, k=0, t=0; for (i=0;i<2;i++) { for (j=0;j<4;j++) // c数组的每个数 { t = 0; // 在这里初始化,不然和会一直累加 for (k=0;k<3;k++) // 一个公用的数 t += a[i][k] * b[k][j]; //计算乘积和 c[i][j] = t; //给予c数组的每个数 } } // 输出c数组 for (i=0;i<2;i++) { for (j=0;j<4;j++) { printf ("%d\t", c[i][j]); } printf ("\n"); } return 0; }运行结果:
标签:
原文地址:http://blog.csdn.net/benjavan4641/article/details/51131879