描述:
在一個(gè)5×6矩陣b中查找最大值的元素以及其所在的行號(hào)和列號(hào)。
輸入:
輸入5行,每行輸入6個(gè)整數(shù),整數(shù)之間用空格隔開(kāi)。
輸出:
在第一行中按格式“max=××”輸出一個(gè)整數(shù)××,即矩陣b的最大值;在第二行中按格式“row=××”輸出一個(gè)整數(shù)××,即最大值所在的行號(hào);在第三行中按格式“column=××”輸出一個(gè)整數(shù)××,即最大值所在的列號(hào)。
輸入樣例 1:?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-522455.html
73 58 62 36 37 79 11 78 83 73 14 47 87 81 43 96 88 15 95 42 57 79 14 63 52 36 66 68 33 35
輸出樣例 1:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-522455.html
max=96 row=2 column=3
#include <stdio.h>
int main(void)
{
int b[5][6], i, j, max, row, column;
for ( i=0;i<5;i++ ) {
for ( j=0;j<6;j++ ) {
scanf("%d", &b[i][j]);
}
}
max = b[0][0];
for ( i=0;i<5;i++ ) {
for ( j=0;j<6;j++ ) {
if ( b[i][j]>max ) {
max = b[i][j];
row = i;
column = j;
}
}
}
printf("max=%d\n", max);
printf("row=%d\n", row);
printf("column=%d\n", column);
return 0;
}
到了這里,關(guān)于在矩陣中查找最大值的元素 以及其所在的行號(hào)、列號(hào)(C語(yǔ)言)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!