Print Vector in C

-1

I would like to start a vector [300] and another [500], but in a way that looks like an array for the user ... for example, I made one of [100], where I looped to start this vector and an "if" for it to break the line so that when it arrived in divisible values by 10 it realized as said.

for(l=0;l<100;l++){
if(l%10==0) // if de quebra de linha 
printf("\n");
if(vetorCEM[l]==0)
printf("[%2d]-",l+1);

The second if is just to show the explicit content of my vector, but what I want to highlight is this example I used, but for the 300 and 500 I did not succeed, I would like someone to help me, plisss !!

    
asked by anonymous 13.12.2018 / 03:00

3 answers

1

Your code worked 100 because 100 is a perfect square (a number that has an entire root), that is, the matrix is 10x10, now 300 and 500 are not ... If your goal is to get a matrix with number of rows and columns equal, in these values will be impossible, now if this is not necessary, you can use any relation, even that of i% 10 to achieve a result or some other that approximates the number of rows with the number of columns ex: for 300, i% 30 that will stay 30x10 and so on.

    
13.12.2018 / 03:10
0

Remember that vector positions start at 0 and end at x - 1, where x is the size of the vector. So the if of line break should look like this: if((i + 1) % y == 0) , where:

i: counter;

y: position of line break.

    
14.12.2018 / 01:23
-2

I think it is not possible, because one element of an array is the intercession of 2 vectors. Create a m[300][500] array and use 2 for :

for(int i = 0; i<300; i++)
{
    for(int j = 0; j <500; j++)
    {
        Printf("%d ",m[i][j]);
    }
}
    
13.12.2018 / 03:09