发布网友 发布时间:2022-04-26 22:54
共2个回答
热心网友 时间:2022-06-19 12:39
运行结果:
int main()
{
int maxNum = 0;
int minNum = 0;
int total = 0;
int test[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
int i,j;
int temp= 0;
for (i = 0;i<3;i++)
{
temp = test[i][0];
for (j = 1;j<4;j++)
{
if (temp < test[i][j])
{
temp =test[i][j];
}
}
printf("第%d行最大的数是:%d\n",i+1,temp);
}
for (j = 0;j<4;j++)
{
temp = test[0][j];
for (i = 1;i<3;i++)
{
if (temp > test[i][j])
{
temp =test[i][j];
}
}
printf("第%d列最小的数是:%d\n",j+1,temp);
}
maxNum = test[0][0];
minNum = test[0][0];
for (i = 0;i<3;i++)
{
for (j = 1;j<4;j++)
{
total +=test[i][j];
if (maxNum < test[i][j])
{
maxNum =test[i][j];
}
if (minNum> test[i][j])
{
minNum =test[i][j];
}
}
}
printf("二维数组的最大值是%d,最小值是%d,总和是%d\n",maxNum,minNum,total);
}
热心网友 时间:2022-06-19 12:40
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (){
int a,b,c=0,i,j,s[3][4],u[3],v[4],max=-1,min=10000;
srand((unsigned)time(NULL));
for(j=0;j<4;j++) v[j]=2000;
for(i=0;i<3;i++)
u[i]=-1;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
a = rand()%400;
s[i][j]=a;
c=c+a;
if(u[i]<s[i][j])
u[i]=s[i][j];
}
}
for(i=0;i<4;i++){
for(j=0;j<3;j++){
if(v[i]>s[j][i])
v[i]=s[j][i];
}
}
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<4;j++){
printf("%d ",s[i][j]);
}
}
for(i=0;i<3;i++){
for(j=0;j<4;j++){
if(s[i][j]>max) max=s[i][j];
if(s[i][j]<min) min=s[i][j];
}}
printf("\n总和%d\n:",c);
printf("行最大:\n");
for(j=0;j<3;j++)
printf("%d ",u[j]);
printf("\n列最小:\n");
for(j=0;j<4;j++)
printf("%d ",v[j]);
printf("全体最大%d ,全体最小值%d\n",max,min);
return 0;
}