Jump to content

Recommended Posts

Posted

Boas,

É possível fazer uma matriz por exemplo assim:

[1][2][3][4]

[5][6][7][8]
 

apenas com 2 for's e dois arrays e que seja possível prosseguir a numeração mantendo a estrutura de 4 digitos por linha?

Posted
int array1[4];
int array2[4];

int n = 1;
for(int i; i < 4; i++)
{
	array1[i] = n;
        n++;
}

for(int i; i < 4; i++)
{
  	array2[i] = n;
  	n++;
}

//2
int array[4][2];
int x = 4;
int y = 2;
int n = 1;
for(int i = 0; i < y; i++)
{
  	for(int w = 0; w < x; w++)
        {
          	array[w][i] = n;
          	n++;
        }
}

//3
#define X 4
#define Y 2
int array[X][Y];
int x = X, y = Y - 1;
for(int i = 0; i < X * Y; i++)
{
  	int old_x = x;
  	int old_y = y;
  
  	x--
        if(x < 0)
        {
          	x = X - 1;
         	y--;
        }
  	
  	if(old_x >= X) 
          	array[x][y] = 8;
  	else
  		array[x][y] = array[old_x][old_y] - 1;
}

Claro que não é possivel :]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.