Dev - C++ - ¿Cómo puedo generar una matriz zig zag de este tipo en C++?

 
Vista:
sin imagen de perfil

¿Cómo puedo generar una matriz zig zag de este tipo en C++?

Publicado por Pancho (1 intervención) el 18/11/2021 07:33:56
Estoy trabajando enC++ y tengo que hacer la impresión de una matriz que muestre los números del 1 al 9 como se muestra en la imagen ingresada:




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//BIBLIOTECAS
#include <iostream>
using namespace std;
 
//PROTOTIPOS DE FUNCIONES
void Leer ( int X[][3]);
void Imprimir ( int X[][3]);
 
//PROGRAMA PRINCIPAL
int main ( void )
{
	int X[3][3];
 
	Leer(X);
	Imprimir(X);
 
	return 0;
}
 
//PROTOTIPOS DE FUNCIONES
void Leer ( int X[][3])
{
	cout <<endl<< "\tBienvenido"<<endl<<endl;
    cout << "\tEste programa: "<<endl;
    cout << "\t1. Lee los datos asignados para la matriz."<<endl;
	cout << "\t2. Imprime los datos ingresados a la matriz."<<endl<<endl;
	cout <<"\tFavor de ingresar los datos de la matriz."<<endl;
  for(int i=0;i<3;i++)
  {
  	for(int j=0;j<3;j++)
  	{
  		cout << "\tX[" << i << "][" << j << "]: ";
  		cin >> X[i][j];
	}
 
  }
}
 
void Imprimir ( int X[][3])
{
	cout <<endl<< "\tLa matriz es: "<<endl;
  for(int i=0;i<3;i++)
  {
  	for(int j=0;j<3;j--)
  	{
  		 cout <<"\t    " <<X[i][j];
	}
  		cout<<endl;
	}
 
}
Sin-titulo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder