c语言 3 4的矩阵,编程序求出其中最大的那个元素的值,以及其所在的行号和列号 (打擂台算法)

               

有一个3*4的矩阵,要求编程序求出其中最大的那个元素的值,以及其所在的行号和列号。(打擂台算法)

解:程序:

#include<stdio.h>

int main()

{

 int i, j, row = 0, colum = 0, max;

 int a[3][4] = { { 1,2,3,4 },{ 4,5,6,7 },{-1,3,-5,10} };

 max = a[0][0];

 printf("array a:\n");

 for (i = 0; i <= 2; i++)

 {

  for (j = 0; j <= 3; j++)

  {

   printf("%5d", a[i][j]);

  }

  printf("\n");

 }

 for (i = 0; i <= 2; i++)

 {

  for (j = 0; j <= 3; j++)

  {

   if (a[i][j] > max)

   {

    max = a[i][j];

    row = i;

    colum = j;

   }

  }

 }

 printf("max=%d\nrow=%d\ncolum=%d\n",max,row,colum);

 return 0;

}

结果:

array a:

    1    2    3    4

    4    5    6    7

   -1    3   -5   10

max=10

row=2

colum=3

请按任意键继续. . .


本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1746397

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43667626/article/details/86656513
今日推荐