Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Elucidation of terms in arrays:
Let us consider an example:
int a [5] = {5,6,1,0,-1};
In the above one-dimensional array, the size is 5, hence this array can accommodate only 5 integer values. Here, 5,6,1,0 and -1 are known as elements of an array, which are stored at specific indices, for instance index of element ‘5’ is ‘0’. The minimum valued element in the above array is ‘-1’ and its index is ‘4’, similarly maximum valued element is ‘6’ and its index is ‘1’. Similar is the case for two-dimensional arrays as well, if we say the sum of all elements in the above onedimensional array then the output should be ‘4+6+1+0+(-1)=10’, considering the above explanation you are advised to write the full implementation of the below function prototypes.
int array1DMinValueElement(int[ ]);
int array1DMinValueElementIndex(int[ ]);
int array2DMinValueElement(int [ ] [COL]);
int array2DMinValueElementIndex(int[ ][COL]);
int array2DMaxValueElement(int[ ] [COL]);
int array2DMaxValueElementIndex(int[ ][COL]);
int array1DMaxValueElement(int[ ]);
int array1DMaxValueElementIndex(int[ ]);
int sum1DArrayElements(int [ ]);
int sum2DArrayElements(int [ ] [COL]);
void matrixProduct(int [ ] [COL], int [ ] [ COL]);

What I have tried:

How can I write the full implementation of the function prototypes?



// This program demonstrates how to find the value with maximum value in a 2-dimensional array

#include <iostream> // pre-processor directive

using namespace std; // uses classes or functions from the "std" namespace

const int ROW = 2; // defining 2 as the number of rows
const int COL = 2; // defining 2 as the number of columns

// function prototype
int array2DMaxValueElement(int[][COL]);


// main function - where program execution takes place
int main()
{

int maxValueElement[ROW][COL];
int i;
int j;


for (i=0;i<row;i++)
{
=""
="" for="" (j="0;j<COL;j++)
" cout="" <<="" "enter="" the="" elements="" this="" 2-d="" array:="" ",="" i+1,="" j+1;
="" cin="">> maxValueElement[i][j];

}

}

cout << array2DMaxValueElement(maxValueElement);

}

// function definition
int array2DMaxValueElement(int element[][COL])
{

// variable declaration
int maxValue;
int i; // variables used for for-loops
int j; // variables used for for-loops


maxValue = element[0][0];

for(i=0;i
Posted
Updated 9-Jul-20 19:43pm
Comments
Andre Oosthuizen 10-Jul-20 1:34am    
This looks like homework, you then post a copied-paste example from another site without reading and learning what arrays are all about and then ask us to write the function for you, sorry, ain't happening.
Rick York 10-Jul-20 3:04am    
I recommend two things : learn how to generate random numbers so you can have random arrays because you will get tired of entering values very quickly. If you don't want random arrays then read them in from a file. Either way, you will be glad you did. The other thing is write two output functions for yourself. One to output 1D arrays and one for 2D. You don't need any more than those two and you certainly don't want to duplicate that code all over the place either.

1 solution

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900