Such as: input array is:
1 2 3 4
0 8 3 1
3, 5, 7 1
Output: 6
CodePudding user response:
Address code: just use a double loop type, a double cycle comparison and accumulation, specific as follows
#include
using namespace std;
Int the sum (int (* ar) [4]) {
Int all=0;
Int var.
int i, j;
for (i=0; i <4. + + I) {
Var=ar [0] [I];
For (j=1; J & lt; 3; + + j)
{
If (var & gt; Ar [j] [I])
Var=ar [j] [I];
}
All +=var.
}
Return all;
}
Int main ()
{
int i, j;
Int ar [3] [4];
for (i=0; i <3; + + I)
For (j=0; J & lt; 4. + + j)
Cin & gt;> Ar [I] [j];
Cout & lt;return 0;
}
CodePudding user response:
Upstairs is a c + +, translated into c
# define _CRT_SECURE_NO_WARNINGS
#include
#include
Int mArray (int myArr [] [4])
{
Int I=0, j=0, min=0, sum=0;
for (i=0; i <4. I++)
{
Min=myArr [0] [I];
For (j=0; J & lt; 3; J++)
{
If (min & gt; MyArr [j] [I])
{
Min=myArr [j] [I];
}
}
The sum +=min;
}
return sum;
}
Int main (void)
{
Int arr [3] [4]={0};
Int I=0, j=0, sum=0;
Printf (" input array elements: \ n ");
for (i=0; i <3; I + +)
{
For (j=0; J & lt; 4. J++)
{
The scanf (" % d ", & amp; Arr [I] [j]);
}
}
Sum=mArray (arr);
Printf (" % d \ n ", sum);
getchar();
return 0;
}
CodePudding user response:
Upstairs is right,Int mArray (int myArr [] [4])
{
Int I=0, j=0, min=0, sum=0;
for (i=0; i <4. I++)
{
Min=myArr [0] [I];
For (j=0; J & lt; 3; J++)
{
If (min & gt; MyArr [j] [I])
{
Min=myArr [j] [I];
}
}
The sum +=min;
}
return sum;
} of this paragraph is the topic request you
A variable name can be set