Dev - C++ - Arreglos, burbuja c++

 
Vista:
sin imagen de perfil

Arreglos, burbuja c++

Publicado por Luis (1 intervención) el 22/04/2018 00:00:10
hola, necesito ayuda con un programa de arreglo de matrices en c++. El programa corre pero no funciona muy bien, lo que quiero es que el numero menor de la matriz este en la parte superior derecha y valla ordenandose de manera horizontal. Les dejo el programa por si me pueden ayudar.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "iostream"
using namespace std;
int main(){
int a,b,i,u,j,x,y,t;
cout<<"INTRODUZCA EL Nro DE FILAS:  ";
cin>>a;
cout<<"INTRODUZCA EL Nro DE COLUMNAS:  ";
cin>>b;
    int M[a][b];
    for(i=1; i<=a; i++){
        for(j=1; j<=b; j++)
        {
             cout<<"Introducir Datos: ";
             cin>>M[i][j];
        }
    }
cout<<"Los Datos De La Matriz Fueron Introducidos Asi: "<<endl;
    for(i=1; i<=a; i++){
        for(j=1; j<=b; j++)
        {
            cout<<M[i][j]<<"  ";
        }
        cout<<endl;
    }
for(i=1; i<=a; i++){
        for(j=1; j<=b; j++)
        {
            for(x=1; x<=a; x++)
            {
                for(y=1; y<=b; y++)
                {
                    if(M[i][j]<M[x][y])
                    {
                        t=M[i][j];
                        M[i][j]=M[x][y];
                        M[x][y]=M[i][j];
                        M[x][y]=t;
                    }
 
                }
            }
         }
    }
    for(i=1; i<=a; i++)
    {
        for(j=1; j<=b; j++)
        {
        }
        }
 
 
   for (i=1; i<=a; i=i+2){
       for(j=1; j<=b; j++)
        {
         if(M[i][b]>M[i][j]){
            u=M[i][b];
            M[i][b]=M[i][j];
            M[i][j]=M[i][b];
            M[i][j]=u;
                    }
 
                }
            }
    cout<<"lombriz:  "<<endl;
    for(i=1; i<=a; i++)
    {
        for(j=1; j<=b; j++)
        {
            cout<<M[i][j]<<"  ";
        }
        cout<<endl;
    }
 
    cout<<endl;
 
 
}
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