Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Filling specific elements in an array

$
0
0
Well, consider this question for a moment:

Quote

Write a program that uses a 2-Dimensional array with 5 rows and 5 columns (i.e. 5 x
5). Your program should do the following:
1. Initialise all elements in the array to the number 5.
2. Set all the elements on the diagonals to 0.


I'm not allowed hardcode, so I assume I have to use a for-loop. Being honest, I have no idea how to do this question, but I'll give what I got so far.

#include <stdio.h>
#define ROW 5
#define COL 5
#define SIZE 10
main()
{
    int array1[ROW][COL] = { {5, 5, 5, 5, 5},
                             {5, 5, 5, 5, 5},
                             {5, 5, 5, 5, 5},
                             {5, 5, 5, 5, 5},
                             {5, 5, 5, 5, 5}
                         };
    int i, j;
    
    for (i = 0; i < ROW; i++)
    {
        for (j = 0; j < COL; j++)
        {
            array1[0][0] = 0;
        }
    }
    


Can anybody hint me in the right direction for this problem? It's probably simple and I am not catching on, but I can be oblivious sometimes.. Cheers!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>