Can anyone teach me how to assign a empty array to zero? Which means that some of the
c[x][y] have not assigned to a value.

``````int x = 4;
int y = 4;
a[x] = {30,40,50,60};
b[y] = {100,20,60,40};
c[x][y];
int i = 0;
int j = 0;
while(i<x && j<y){
if(a[i]<b[j]){
c[i][j] = a[i];

}
}``````

I would look at two for loops

``````for (int i  0; i < x; ++i)
{
for (int j = 0; j < y; ++j)
{

}
}``````

Please explain in detail. I, for one, am confused by your request.

``````int x = 4;
int y = 4;
a[x] = {30,40,50,60};
b[y] = {100,20,60,40};
c[x][y];
int i = 0;
int j = 0;
while(i<x && j<y){
if(a[i]<b[j]){
c[i][j] = a[i];

else if(a[i]>b[j]){
c[i][j] = b[j];
}
}
}``````

what i mean is not all the arrays of c[][] are assigned to a value, and after that i need to display it out on a table, but the computer juz simply give me a random value of the unassigned array.like.

30 40 -1232312321 30
40 121231234 40 50

Hope you all know what am i asking ><''

So initialize the matrix to all 0's first.

Is it safe to assume that there is more to this code somewhere? I ask this because the index values never get changed in the code as given, which would result in an endless loop.

As for initializing the arrays to zero, the best approach is the one given by Gerard4143 earlier: iterate through the array of arrays and clear all of the values, before using them arrays. If you want a general solution to clearing blocks of memory (which is exactly what arrays are), you can use memset().

So initialize the matrix to all 0's first.

woot!solved! thanks!

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.