// Pantea Aria // static 2D arrays: similar to a Matrix // Write a program that declares the following square 2D array of integers // { // {1, 0, -1}, // {2, -2, 4}, // {0, 5, 3} // } // and prints the sum of all main diagonal elements with a function. // The main diagonal runs from the top-left to the bottom-right. // your turn: sum of all rows // your turn: sum of all columns // your turn: sum of all secondary diagonal elements (top-right to the bottom left) #include int main(void) { int array[3][3] = {{1, 0, -1}, {2, -2, 4}, {0, 5, 3}}; int i = 0; while(i < 3) { int j = 0; int row_sum = 0; while(j < 3) { row_sum = row_sum + array[i][j]; j++; } // what is row_sum? // it is the sum of all integers in row i printf("Sum of all int in row %d is %d\n", i, row_sum); i++; } return 0; }