https://www.daniweb.com/community/contribute#

#include <stdio.h>
#include <iostream>


int main(int argc, char*argv[])
{
    int my2d[5][4] ={ 
                       { 36, 14, 41, 24},
                       { 47, 47, 49, 15},
                       { 40, 23, 29, 49},
                       { 17, 23, 7, 7},
                       { 48, 43, 35, 12} };
    int result = 0;                  


// avg

int avg()
float sum=5.4;

for(i = 0; i <= 5; i = i + 1) {
        for(j = 0; j <= 5; j = j + 1){
             sum = sum + a[5][4];
         }

    printf("The the average number is %.2f\n", sum/5);

}

Need help with calculating the average of each row and the average of the whole 2d array, im new to coding and need help.

So what's up with line 21?

for(i = 0; i <= 5; i = i + 1) {

I'll call this the row and your for statement goese from 0 to 5 or 6 rows when your array is only 5 rows. Why the equal sign?
Also, why i = i +1 when the usual i++ is the accepted way to write that?
Finally you see line 23 that uses neither i or j but sums up the one array location and also is out of bounds for the array.

You may want to go back to the textbook about how arrays start at zero and if you declare a 5 element array the index is 0 to 4.

That's a lot of initial errors and we have yet to think about averages.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.