Adsence

Mostrando entradas con la etiqueta ciclo. Mostrar todas las entradas
Mostrando entradas con la etiqueta ciclo. Mostrar todas las entradas

martes, 27 de agosto de 2013

Mover elemento de una matriz hasta la posición indicada

2 comments
Este programa permite poder mover un elemento 'A' hasta un elemento 'B' de una matriz y que cuando llegue a 'B' deje de mover el elemento 'A'.

 

icn-C++

[codesyntax lang="cpp"]
#include <iostream>
using namespace std;
void imprimirMatriz(char matriz[9][9],int n,int m)
{

}
int main () {

int n,m,x,y,w,z;
int f,c;
cin>>n>>m;
char matriz [n][m];

for (f = 0; f < n; f++)
{
for (c = 0; c < m; c++)
{
cin>>matriz [f][c];

if (matriz [f][c] == 'A')
{
x = f;
y = c;
}

if (matriz [f][c] == 'B')
{
w = f;
z = c;
}

}
}

for (f = 0; f < n; f++)
{
cout<<endl;
for (c = 0; c < m; c++)
{
if(matriz[f][c]=='B')
{
//Termino el programa
matriz[f][c]='A';
c=m;
f=n;
}else{
if(matriz[f][c]=='A')
{
matriz[f][c]='.';
}else{
matriz[f][c]='.';
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<matriz[i][j];
}
cout<<endl;
}

}
}
cout<<"n"<<endl;

return 0;
}

[/codesyntax]
Read More...