elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Matrices en C++ ayuda en: 3 Abril 2018, 09:50 am
Necesito hacer una matriz de nxn y que me los imprima en modo de lluvia ejemplo

 en dado caso una matriz 3x3 seria asi 4 7 9
                                                        2 5 8
                                                        1 3 6
o sea lo de hacerla nxn lo tengo claro pero a la hora de imprimirla asi me tranca, no puedo usar punteros, solo arreglos
2  Programación / Programación C/C++ / Laberinto c++ en: 19 Marzo 2018, 21:21 pm
buenas tengo estos dos laberintos y se supone que con esa condicion que le puse al while deberia salirse e imprirmirse el otro pero solo se come la x y sigue como si nada en el mismo laberinto esto es lo que llevo, pls help


#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
void laberinto(int a[10][25],int f,int c){
   int i,j;
   for(i=0;i<f;i++){
   for(j=0;j<c;j++)
      if(a[j]==0) cout<<" ";
         else if(a[j]==1) cout<<"@";
            else if(a[j]==2) cout<<"x";
               else cout<<"X";
                  cout<<endl;
}


}

void laberinto2(int b[15][45],int fi, int co){
   int l,m;
   for(l=0;l<fi;l++){
   for(m=0;m<co;m++)
      if(b[l][m]==0) cout<<" ";
         else if(b[l][m]==1) cout<<"@";
            else if(b[l][m]==2) cout<<"x";
               else cout<<"X";
                  cout<<endl;
}
}
int main(void){

int a[10][25]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},
{2,0,0,0,0,1,0,1,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1},
{1,1,0,1,1,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,1},
{1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,1,0,1,1,1,0,0,1},
{1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,1,0,1},
{1,1,0,0,0,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int x=0,y=1;
char opc;
do{
system("cls");
laberinto(a,10,25);
opc=getch();
if(opc=='w'&& a[y-1]
  • !=1){a[y]
  • =0;y--;a[y]
  • =2;}
if(opc=='s'&& a[y+1]
  • !=1){a[y]
  • =0;y++;a[y]
  • =2;}
if(opc=='a'&& a[y][x-1]!=1){a[y]
  • =0;x--;a[y]
  • =2;}
if(opc=='d'&& a[y][x+1]!=1){a[y]
  • =0;x++;a[y]
  • =2;}



 }while(opc=a[6][20] &&opc!='x');
 
 
 
do{
system("cls");
laberinto2(b,15,45);
opc=getch();
if(opc=='w'&& b[y-1]
  • !=1){b[y]
  • =0;y--;b[y]
  • =2;}
if(opc=='s'&& b[y+1]
  • !=1){b[y]
  • =0;y++;b[y]
  • =2;}
if(opc=='a'&& b[y][x-1]!=1){b[y]
  • =0;x--;b[y]
  • =2;}
if(opc=='d'&& b[y][x+1]!=1){b[y]
  • =0;x++;b[y]
  • =2;}



 }while(opc=a[0][1] &&opc!='x');
 }
 
 

Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines