Jump to content
Iago Marques

Ordenar valores da matriz em ordem crescente

Recommended Posts

Iago Marques

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]);

      }
    }

}

 

Share this post


Link to post
Share on other sites
HappyHippyHippo

- qual é o sentido deste tópico ?

- qual o significado de valores da matriz ?

- qual o indicador de "crescente" ?

 


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
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.