There is a 3*4 matrix that requires the program to find the value of the largest element in it, along with its line number and column number. (Daleitai algorithm)
Solution: Program:
#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;
}
Results:
Array A:
1 2 3 4
4 5 6 7
-1 3-5 10
max=10
row=2
Colum=3
Please press any key to continue ...
This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1746397
C Language: 3*4 Matrix, the program to find the largest of the elements of the value, as well as the line number and the column number. (Daleitai algorithm)