Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- /// Autor Gustavo Riposati
- int main()
- {
- int m[5][5];
- int i,j;
- int vet[5];
- srand((unsigned)time(NULL));
- /// inicializando a matriz c qlqr numero entre 0 e 100
- for(i=0;i<5;i++){
- for(j=0;j<5;j++){
- m[i][j] = rand() % 100;
- }
- }
- /*********************************/
- ///matriz original
- printf("matriz original = \n");
- for(i=0;i<5;i++){
- for(j=0;j<5;j++){
- printf("%d ",m[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- /***********************************************/
- for(i=0;i<5;i++){
- for(j=0;j<5;j++){
- vet[j] = m[j][i];
- //printf("pos atual = %d\n",m[j][i]);
- }
- ///precisa ordenar aqui depois de pegar a coluna
- ///ordenação por bolha, bubble sort
- int aux,z,x;
- for(z=0;z<5;z++){
- for(x=0;x<4;x++){
- if(vet[x] > vet[x+1]){
- aux = vet[x+1];
- vet[x+1] = vet[x];
- vet[x] = aux;
- }
- }
- }
- /// mostrando o vetor já ordenado e voltando os valores pra matriz
- int t;
- printf("o vetor com os dados da coluna %d ja ordenados\n",i+1);
- for(t=0;t<5;t++){
- printf("[%d] ",vet[t]);
- m[t][i] = vet[t];
- }
- printf("\n");
- }
- /************************************/
- printf("\n\nmatriz com as colunas ordenadas\n");
- for(i=0;i<5;i++){
- for(j=0;j<5;j++){
- printf("%d ",m[i][j]);
- }
- printf("\n");
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement