Created
December 10, 2022 14:28
-
-
Save pvpassos/389f776c59828e621442e79c618bcba9 to your computer and use it in GitHub Desktop.
CORPO DO PROGRAMA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // arquivo *.c da Biblioteca | |
| #include<stdio.h> | |
| #include <string.h> // utilizada na função leitura_txt() | |
| #include <stdlib.h> | |
| void leitura_txt(int *linhas, int *colunas, float matriz[][20]) | |
| { | |
| FILE *arq; | |
| char Nome[128]; | |
| char Linha[100]; | |
| char *result; | |
| int li , col; | |
| int i, j; | |
| // Entra com o nome (caminho) do ARQUIVO via TECLADO | |
| printf("\n\nNome do Arquivo .TXT sem a extensao:\n"); | |
| scanf("%123s", Nome); | |
| strcat(Nome, ".txt"); | |
| // Abre um arquivo TEXTO para LEITURA | |
| arq = fopen(Nome, "rt"); | |
| if (arq == NULL) // se houve erro na abertura | |
| { | |
| printf("Problemas na abertura do arquivo\n"); | |
| return; | |
| } | |
| result = fscanf(arq,"%d%d", &li, &col); | |
| *linhas = li; | |
| *colunas = col; | |
| printf("\nArquivo: %s tem", Nome); | |
| printf("\n%d linhas e %d colunas\n", li, col); | |
| // Inicia os contadores | |
| i,j = 0; | |
| for (i = 0; i < li; i++) | |
| { | |
| for ( j = 0; j < col; j++) | |
| { | |
| result = fscanf(arq,"%f", &matriz[i][j]); | |
| // printf("Valor lido na posicao %d %d = %.1f \n", i, j, matriz[i][j]); // Teste na fase de desenvolvimento! | |
| } | |
| } | |
| printf("\nPara checar: valor da ultima coluna na ultima linha = %.1f\n", matriz[li-1][col-1]); // Teste em execução: Li tudo?! Rsss... | |
| printf("\nPronto... arquivo lido e matriz criada!\n\n"); | |
| fclose(arq); | |
| } | |
| void imprime(int *linhas, int *colunas, float matriz[][20]) | |
| { | |
| printf("\nImprimindo...\n\n"); | |
| int i,j; | |
| for (i = 0; i < *linhas; i++) | |
| { | |
| for (j = 0; j < *colunas; j++) | |
| { | |
| printf("%.1f \t", matriz[i][j]); | |
| } | |
| printf("\n"); | |
| } | |
| printf("\nImprimiu!\n"); | |
| } | |
| void crescente(int *linhas, int *colunas, float matriz[][20]) | |
| { | |
| //receber do usuario a coluna a ordenar | |
| printf("Qual coluna deseja ordenar?\n"); | |
| int colunaEscolhida; | |
| scanf("%d", &colunaEscolhida); | |
| int qtdLinhas = *linhas; | |
| float array[qtdLinhas]; | |
| //colocando a coluna da matriz em um vetor | |
| for (int i = 0; i < qtdLinhas; i++){ | |
| array[i] = matriz[i][colunaEscolhida]; | |
| } | |
| //ordenando com bubble_sort | |
| int aux=0; | |
| for (int i = 1; i < qtdLinhas; i++){ | |
| for (int j = 0; j < qtdLinhas-i; j++){ | |
| if (array[j]>array[j+1]){ | |
| aux = array[j]; | |
| array[j] = array[j+1]; | |
| array[j+1] = aux; | |
| } | |
| } | |
| } | |
| //colocando o vetor ordenado de volta na coluna da matriz | |
| for (int i = 0; i < qtdLinhas; i++){ | |
| matriz[i][colunaEscolhida] = array[i]; | |
| } | |
| //imprimindo a coluna ordenada | |
| printf("Coluna %d ordenada abaixo\n\n", colunaEscolhida); | |
| for (int i = 0; i < qtdLinhas; i++){ | |
| printf("%.1f \t", matriz[i][colunaEscolhida]); | |
| } | |
| printf("\nImpresso com sucesso\n"); | |
| } | |
| void decrescente() | |
| { | |
| printf("Em ordem descrescente\n"); | |
| } | |
| void maior() | |
| { | |
| printf("Maior valor\n"); | |
| } | |
| void menor() | |
| { | |
| printf("Menor valor\n"); | |
| } | |
| void repetidos() | |
| { | |
| printf("Repetido?\n"); | |
| } | |
| void sair() | |
| { | |
| printf("Obrigado, espero ter sido util!\n\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment