Jump to content
Fórum Script Brasil
  • 0

Alguém me ajuda a ordenar os valores de uma matriz em ordem crescente?


Question

Segue-se o código abaixo!!!

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <locale.h>

#define lin 2
#define col 2

main(){

    setlocale(LC_ALL, "Portuguese");

    int mat[lin][col], l, c, temp;

    for(l=0; l<lin; l++){

        printf("- Linha [%i]", l);

      for(c=0; c<col; c++){

        printf("\n\t- Coluna [%i]: ", c);
        scanf("%i", &mat[l][c]);

      }

    }

    for(l=0; l<col; l++){

      for(c=l+1; c<col; c++){

        if(mat[l][c] > mat[c][l])

          temp = mat[l][c];
          mat[l][c] = mat[l][c];
          mat[c][l] = temp;

      }

    }

    printf("\nMatriz em Ordem Crescente.");

    for(l=0; l<lin; l++){

        printf("\n\n");

      for(c=0; c<col; c++){

        printf("\t [%i]", mat[l][c]);

      }
    }

}

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148743
    • Total Posts
      644621
×
×
  • Create New...