gpt4 book ai didi

c - 如何打印我在二维数组中找到最大数字的行?

转载 作者:行者123 更新时间:2023-11-30 18:45:46 25 4
gpt4 key购买 nike

我知道如何找到最大的数字,但不知道如何打印该行?........................................ ...................................................... ...................................................... …………

#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main()
{
int i,j,n, max_i, max_j;
printf("Input size of a matrix:");
scanf("%d", &n);
int mat[n][n];


printf("Input numbers in matrix:");
for (i=0;i<n;i++){
for (j=0;j<n;j++){
scanf("%d", &mat[i][j]);
}
}
max_i=0;
max_j=0;
for (i=0;i<n;i++){
for (j=0;j<n;j++){
if(mat[max_i][max_j]>mat[i][j]){
mat[i][j]=mat[max_i][max_j];
}
}
}
printf("Largest number is %d, print of his whole row is %d", mat[max_i][max_j], mat[i][0] ); // I think here is a problem, but who knows
return 0;
}

最佳答案

如果谷歌翻译正确,并且我明白你想要什么 - 那么你需要将其一一打印出来,或者在循环之前收集:

printf("Najveci broj je %d, a ispis cijelog retka je ", mat[max_i][max_j]);
for(j = 0; j < n; j++) {
printf("%d ", mat[max_i][j]);
}

关于c - 如何打印我在二维数组中找到最大数字的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53610334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com