Created
January 2, 2014 11:47
-
-
Save novnan/8218101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 求二维数组iData[M][N]中最大元素所在的行和列 | |
#include <stdio.h> | |
#define M 3 | |
#define N 4 | |
void main() | |
{ | |
int i, j, iData[M][N]; | |
int *p, *pMax; | |
printf("请按行输入%d x %d数组的各元素:\n", M, N); | |
for(p = &iData[0][0]; p <= iData[M - 1] + N -1; p++) | |
{ | |
scanf("%d", p); | |
} | |
printf("输入的数组是:"); | |
for(p = iData[0]; p <= iData[M - 1] + N - 1; p++) | |
{ | |
if(((p - iData[0]) % N) == 0) printf("\n"); // 什么意思 // 按行打印二维数组 | |
printf("%5d", *p); | |
} | |
pMax = iData[0]; | |
for(p = iData[0]; p <= iData[M - 1] + N - 1; p++) | |
{ | |
if(*p > *pMax) pMax = p; | |
} | |
i = (pMax - iData[0]) / N; // 什么意思 | |
j = (pMax - iData[0]) % N; | |
printf("\n最大值在第%d行第%d列\n", i + 1, j + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment