Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i have an error excess element in array initializer at int num[NUM_ROWS][NUM_COL

ID: 3540738 • Letter: I

Question

i have an error excess element in array initializer at


int num[NUM_ROWS][NUM_COLS]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};


please point me out why there is an error and show me how to fix it... here is my code try take a look why is an error.







#include<iostream>
using namespace std;

#define NUM_ROWS 2
#define NUM_COLS 2



//Declare functions
int getTotal (int[][NUM_COLS]);
double getAverage(int);
int getRowTotal (int[][NUM_COLS], int);
int getColumnTotal (int[][NUM_COLS], int);
int getHighestInRow(int[][NUM_COLS], int);
int getLowestInRow(int [][NUM_COLS], int);
double getAverage(int);

int main ()
{
    //Declare varaiable
    
    int n=2;
    int num[NUM_ROWS][NUM_COLS]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    
    cout<<"total values of value in array: "<<getTotal(num)<<endl;
    cout<<"average values of all value in array: "<<getAverage(num)<<endl;
    cout<<"total of all value in row "<<n<<" is: "<<getRowTotal(num,n)<<endl;
    cout<<"total of all column "<<n<<" is: " <<getColumnTotal(num,n) <<endl;
    cout<<"highest value in row "<<n<<" is: "<<getHighestInRow(num,n)<<endl;
    cout<<"lowest value in row "<<n<<" is: "<<getLowestInRow(num,n)<<endl;
    
    return 0;
}
int getTotal (int row[] [NUM_COLS])
{
    int i,j,value=0;
    
    for(i=0;i<NUM_ROWS;i++)
        for (j=0;j<NUM_COLS;j++)
            value+=row[i][j];
    return value;
}
//this function getaverage
double getAverage (int totalValues)
{
    double avg;
    avg=totalValues/ (NUM_ROWS*NUM_COLS);
    return avg;
}
//this function getrowtotal
int getRowTotal (int num[][NUM_COLS], int n)
{
    int i,value=0;
    
    for(i=0;i<NUM_COLS;i++)
        value+=num[n][i];
    return value;
}
//this function get column
int getColumnTotal(int num[][NUM_COLS],int n)
{
    int i, value=0;
    
    for (i=0;i<NUM_ROWS;i++)
        value+=num[i][n];
    return value;
}
//this function gethighestinrow
int getHighestInRow(int num[][NUM_COLS], int n)
{
    int i,value=0;
    value=num[n][0];
    
    for(i=1;i<NUM_COLS;i++)
        if (num[n][i]>value)
            value=num[n][i];
    return value;
}
//this function get getlowestinrow
int getLowestInRow(int num[][NUM_COLS], int n)
{
    int i, value=0;
    value=num[n][0];
    
    for (i=1;i<NUM_COLS;i++)
        if (num[n][i]<value)
            value=num[n][i];
    return value;
}

Explanation / Answer

U have defined Number of rows and coloumns is 2 and trying to store more number of intiger values , Please increase the size of the matrix and try