Jump to content

Ordenar valores da matriz em ordem crescente

Iago Marques

Recommended Posts

Código abaixo: 

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

#define lin 2
#define col 2


    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++){


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

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


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.