quinta-feira, 6 de dezembro de 2012

Ordenando Colunas de Matriz Bidimensional II

Neste programa eu mostro um dos métodos de ordenar. uma matriz por colnas, a matriz é do tipo int e a ordenação é pelo método da bolha, sabemos que tem outros métodos mais este é um dos mais fácil de imprementar. A diferença deste código para o outro que postei, é que este criei funções e passei parâmetros a elas, todo iniciante em C tem que aprender passar parâmetros para funções. Uma dica é comparar os dois códigos, a princípio, não é obrigado entender tudo, más é obrigado aprender imprementar estas funções.

Eis a saída deste código no cmd:


#include <stdio.h>
#include <conio2.h>
void bolha(int mat_riz [3] [5], int b);
int mat [3] [5] = {{ 14, 11, 5, 13, 12 },
        { 8, 10, 6, 15, 7 },
        { 2, 3, 1, 4, 9 }};
void ezibe_Matriz (int matriz [3] [5]){
    int i, j;
    printf ("\n");textcolor(YELLOW);
    for ( i = 0; i < 3; ++i){
        printf ("\n");gotoxy(29,i + 7);
        for ( j = 0; j < 5; ++j )
            printf ("%5i", mat [i] [j]);
    }
    getche();
    bolha( mat, 2);
    getche();
}
void bolha(int mat_riz [3] [5], int b){
    int i, j,  ord = 0, aux;
    while(ord == 0){
        ord = 1;
        for(i = 0; i < 2 ; i++){
            for(j = 0; j < 5; j++){
                if( mat_riz  [i] [j]  > mat_riz [(i + 1)] [j]){
                    aux = mat_riz [i] [j];
                    mat_riz [i] [j] = mat_riz [(i + 1)] [j];
                    mat_riz [(i + 1 )] [j] = aux;
                    ord = 0;
                }
            }
        }
    }
    textcolor(LIGHTGREEN);gotoxy(29,11);printf("IMPRIMINDO A MATRIZ ORDENADA");
    printf("\n");textcolor(YELLOW);
    for(i = 0; i < 3; i++){
        printf("\n");gotoxy(29,i + 13);
        for(j = 0; j < 5; j++){
            printf("%5i",  mat_riz [i] [j]);
        }
    }
    Sleep(1800);
    textcolor(LIGHTRED);gotoxy(35,19);printf("\aO ROCCO AGRADECE");
}
int main (){
    system ("title ORDENANDO COLUNAS DE UMA MATRIZ BIDIMENSIONAL II");
    void ezibe_Matriz (int matriz [3] [5]);
    textcolor(LIGHTRED);gotoxy(19,2);printf("ORDENANDO COLUNAS DE UMA MATRIZ BIDIMENSIONAL II");
    textcolor(LIGHTGREEN);gotoxy(29,4);printf("IMPRIMINDO A MATRIZ ORIGINAL");
    ezibe_Matriz (mat);
    return 0;
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.