├── FACULDADE ├── Arvore │ ├── alturaArv.c │ ├── arvore │ └── arvore.c ├── Atividade Prática Prog2 Férias │ ├── AlunosMatriz │ ├── AlunosMatriz.c │ ├── Caminhada │ ├── Caminhada.c │ ├── Conversor │ ├── Conversor.c │ ├── Ordena │ ├── Ordena.c │ ├── ProcurarElemento │ ├── ProcurarElemento.c │ ├── Tiro.c │ ├── VetorOrdInv │ ├── VetorOrdInv.c │ ├── calculaCirculo.c │ ├── concatString.c │ ├── criptografia │ ├── criptografia.c │ ├── malloc.c │ ├── malloc2.c │ ├── premiados │ ├── premiados.c │ └── taximetro.c ├── Lista Encadeada │ ├── lista │ ├── lista.c │ ├── listaSimpEcad.c │ ├── lst.c │ └── lst_encad.c ├── Ponteiros │ ├── ponteiro │ └── ponteiro.c └── Projeto em C │ ├── Atividade pratica1 │ ├── coralperfeito.c │ ├── coralperfeito.exe │ ├── fatorial.c │ └── fatorial.exe │ ├── Lista Struct │ ├── lst.exe │ ├── struct(funcao).c │ ├── struct(funcao).exe │ ├── struct(struct).c │ └── struct.exe │ ├── Lista prog2 │ ├── Realloc.c │ ├── Realloc.exe │ ├── questao1.c │ ├── questao1.exe │ ├── questao3.c │ └── questao3.exe │ ├── Treino de ponteiros │ ├── TrabOred.c │ ├── TrabOred.exe │ ├── TrabProg2Ordenacao.c │ ├── TrabProg2Ordenacao.exe │ ├── a.exe │ ├── listaSimpEcad │ ├── teste.c │ ├── teste.exe │ ├── treinoP1.c │ ├── treinoP1.exe │ ├── treinoP1semvoid.c │ └── treinoP1semvoid.exe │ ├── beecrowd(merda) │ ├── Fissura.exe │ ├── acidAlig.c │ ├── bingo.exe │ ├── botasperdidas.c │ ├── botasperdidas.exe │ ├── cartaFora.c │ ├── churrasyuri.c │ ├── churrasyuri.exe │ ├── corrida.c │ ├── corrida.exe │ ├── interruptor.c │ ├── interruptores.c++ │ ├── interruptores.exe │ ├── paciente0.c │ ├── registradores.c │ ├── registradores.exe │ ├── teclado;c │ ├── testes.c │ └── testes.exe │ └── p2 │ ├── Prova.c │ ├── Prova.exe │ ├── funcoes.c │ ├── funcoes.exe │ ├── p2.exe │ ├── p2q1.c │ ├── p2q2.c │ └── p2q2.exe ├── Fila ├── fila └── fila.c ├── Lista Duplamente Encadeada └── listaDuplaEncad.c ├── Pilha ├── pilha ├── pilha.c ├── testeP └── testeP.c ├── README.md └── Trabalho 2 └── trab.c /FACULDADE/Arvore /alturaArv.c: -------------------------------------------------------------------------------- 1 | /* 2 | Aula 271: Como calcular a ALTURA uma Árvore Binária? 3 | 4 | Código escrito por Wagner Gaspar 5 | Setembro de 2021 6 | */ 7 | 8 | typedef struct no{ 9 | int valor; 10 | struct no *direita, *esquerda; 11 | }NoArv; 12 | 13 | NoArv* inserir_versao_1(NoArv *raiz, int num){ 14 | if(raiz == NULL){ 15 | NoArv *aux = malloc(sizeof(NoArv)); 16 | aux->valor = num; 17 | aux->esquerda = NULL; 18 | aux->direita = NULL; 19 | return aux; 20 | } 21 | else{ 22 | if(num < raiz->valor) 23 | raiz->esquerda = inserir_versao_1(raiz->esquerda, num); 24 | else 25 | raiz->direita = inserir_versao_1(raiz->direita, num); 26 | return raiz; 27 | } 28 | } 29 | 30 | void inserir_versao_2(NoArv **raiz, int num){ 31 | if(*raiz == NULL){ 32 | *raiz = malloc(sizeof(NoArv)); 33 | (*raiz)->valor = num; 34 | (*raiz)->esquerda = NULL; 35 | (*raiz)->direita = NULL; 36 | } 37 | else{ 38 | if(num < (*raiz)->valor) 39 | inserir_versao_2(&((*raiz)->esquerda), num); 40 | else 41 | inserir_versao_2(&((*raiz)->direita), num); 42 | } 43 | } 44 | 45 | void inserir_versao_3(NoArv **raiz, int num){ // 500 46 | NoArv *aux = *raiz; 47 | while(aux){ 48 | if(num < aux->valor) 49 | raiz = &aux->esquerda; 50 | else 51 | raiz = &aux->direita; 52 | aux = *raiz; 53 | } 54 | aux = malloc(sizeof(NoArv)); 55 | aux->valor = num; 56 | aux->esquerda = NULL; 57 | aux->direita = NULL; 58 | *raiz = aux; 59 | } 60 | 61 | NoArv* buscar_versao_1(NoArv *raiz, int num){ // 500 700 850 1000 1500 62 | if(raiz){ 63 | if(num == raiz->valor) 64 | return raiz; 65 | else if(num < raiz->valor) 66 | return buscar_versao_1(raiz->esquerda, num); 67 | else 68 | return buscar_versao_1(raiz->direita, num); 69 | } 70 | return NULL; 71 | } 72 | 73 | NoArv* buscar_versao_2(NoArv *raiz, int num){ 74 | while(raiz){ 75 | if(num < raiz->valor) 76 | raiz = raiz->esquerda; 77 | else if(num > raiz->valor) 78 | raiz = raiz->direita; 79 | else 80 | return raiz; 81 | } 82 | return NULL; 83 | } 84 | 85 | int altura(NoArv *raiz){ 86 | if(raiz == NULL){ 87 | return -1; 88 | } 89 | else{ 90 | int esq = altura(raiz->esquerda); 91 | int dir = altura(raiz->direita); 92 | if(esq > dir) 93 | return esq + 1; 94 | else 95 | return dir + 1; 96 | } 97 | } 98 | 99 | void imprimir_versao_1(NoArv *raiz){ 100 | if(raiz){ 101 | printf("%d ", raiz->valor); 102 | imprimir_versao_1(raiz->esquerda); 103 | imprimir_versao_1(raiz->direita); 104 | } 105 | } 106 | 107 | void imprimir_versao_2(NoArv *raiz){ 108 | if(raiz){ 109 | imprimir_versao_2(raiz->esquerda); 110 | printf("%d ", raiz->valor); 111 | imprimir_versao_2(raiz->direita); 112 | } 113 | } 114 | 115 | int main(){ 116 | 117 | NoArv *busca, *raiz = NULL; 118 | int opcao, valor; 119 | 120 | do{ 121 | printf("\n\t0 - Sair\n\t1 - Inserir\n\t2 - Imprimir\n\t3 - Buscar\n\t4 - Altura\n"); 122 | scanf("%d", &opcao); 123 | 124 | switch(opcao){ 125 | case 1: 126 | printf("\n\tDigite um valor: "); 127 | scanf("%d", &valor); 128 | //raiz = inserir_versao_1(raiz, valor); 129 | //inserir_versao_2(&raiz, valor); 130 | inserir_versao_3(&raiz, valor); 131 | break; 132 | case 2: 133 | printf("\n\tPrimeira impressao:\n\t"); 134 | imprimir_versao_1(raiz); 135 | printf("\n"); 136 | printf("\n\tSegunda impressao:\n\t"); 137 | imprimir_versao_2(raiz); 138 | printf("\n"); 139 | break; 140 | case 3: 141 | printf("\n\tDigite o valor a ser procurado: "); 142 | scanf("%d", &valor); 143 | //busca = buscar_versao_1(raiz, valor); 144 | busca = buscar_versao_2(raiz, valor); 145 | if(busca) 146 | printf("\n\tValor encontrado: %d\n", busca->valor); 147 | else 148 | printf("\n\tValor nao encontrado!\n"); 149 | break; 150 | case 4: 151 | printf("\n\tAltura da arvore: %d\n\n", altura(raiz)); 152 | break; 153 | default: 154 | if(opcao != 0) 155 | printf("\n\tOpcao invalida!!!\n"); 156 | } 157 | }while(opcao != 0); 158 | 159 | return 0; 160 | } -------------------------------------------------------------------------------- /FACULDADE/Arvore /arvore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Arvore /arvore -------------------------------------------------------------------------------- /FACULDADE/Arvore /arvore.c: -------------------------------------------------------------------------------- 1 | /* Implementação de árvore binária */ 2 | 3 | #include 4 | #include 5 | 6 | /* Cada nó armazena três informações: 7 | nesse caso um número (num), 8 | ponteiro para subárvore à direita (sad) 9 | e ponteiro para subárvore à esquerda (sae).*/ 10 | typedef struct tree 11 | { 12 | int num; 13 | struct tree* sad; 14 | struct tree* sae; 15 | } Tree; 16 | 17 | /* A estrutura da árvore é representada por um ponteiro 18 | para o nó raiz. Com esse ponteiro, temos acesso aos 19 | demais nós. */ 20 | 21 | /* Função que cria uma árvore */ 22 | Tree* createTree() 23 | { 24 | /* Uma árvore é representada pelo endereço do nó raiz, 25 | essa função cria uma árvore com nenhum elemento, 26 | ou seja, cria uma árvore vazia, por isso retorna NULL. */ 27 | return NULL; 28 | } 29 | 30 | /* Função que verifica se uma árvore é vazia */ 31 | int treeIsEmpty(Tree* t) 32 | { 33 | /* Retorna 1 se a árvore for vazia e 0 caso contrário */ 34 | return t == NULL; 35 | 36 | } 37 | 38 | /* Função que mostra a informação da árvore */ 39 | void showTree(Tree* t) 40 | { 41 | /* Essa função imprime os elementos de forma recursiva */ 42 | 43 | printf("<"); /* notação para organizar na hora de mostrar os elementos */ 44 | if(!treeIsEmpty(t)) /* se a árvore não for vazia... */ 45 | { 46 | /* Mostra os elementos em pré-ordem */ 47 | printf("%d ", t->num); /* mostra a raiz */ 48 | showTree(t->sae); /* mostra a sae (subárvore à esquerda) */ 49 | showTree(t->sad); /* mostra a sad (subárvore à direita) */ 50 | } 51 | printf(">"); /* notação para organizar na hora de mostrar os elementos */ 52 | } 53 | 54 | /* Função que insere um dado na árvore */ 55 | void insertTree(Tree** t, int num) 56 | { 57 | /* Essa função insere os elementos de forma recursiva */ 58 | if(*t == NULL) 59 | { 60 | *t = (Tree*)malloc(sizeof(Tree)); /* Aloca memória para a estrutura */ 61 | (*t)->sae = NULL; /* Subárvore à esquerda é NULL */ 62 | (*t)->sad = NULL; /* Subárvore à direita é NULL */ 63 | (*t)->num = num; /* Armazena a informação */ 64 | } else { 65 | if(num < (*t)->num) /* Se o número for menor então vai pra esquerda */ 66 | { 67 | /* Percorre pela subárvore à esquerda */ 68 | insertTree(&(*t)->sae, num); 69 | } 70 | if(num > (*t)->num) /* Se o número for maior então vai pra direita */ 71 | { 72 | /* Percorre pela subárvore à direita */ 73 | insertTree(&(*t)->sad, num); 74 | } 75 | } 76 | } 77 | 78 | /* Função que verifica se um elemento pertence ou não à árvore */ 79 | int isInTree(Tree* t, int num) { 80 | 81 | if(treeIsEmpty(t)) { /* Se a árvore estiver vazia, então retorna 0 */ 82 | return 0; 83 | } 84 | 85 | /* O operador lógico || interrompe a busca quando o elemento for encontrado */ 86 | return t->num==num || isInTree(t->sae, num) || isInTree(t->sad, num); 87 | } 88 | 89 | int main() 90 | { 91 | Tree* t = createTree(); /* cria uma árvore */ 92 | 93 | insertTree(&t, 12); /* insere o elemento 12 na árvore */ 94 | insertTree(&t, 15); /* insere o elemento 15 na árvore */ 95 | insertTree(&t, 10); /* insere o elemento 10 na árvore */ 96 | insertTree(&t, 13); /* insere o elemento 13 na árvore */ 97 | 98 | showTree(t); /* Mostra os elementos da árvore em pré-ordem */ 99 | 100 | if(treeIsEmpty(t)) /* Verifica se a árvore está vazia */ 101 | { 102 | printf("\n\nArvore vazia!!\n"); 103 | } else { 104 | printf("\n\nArvore NAO vazia!!\n"); 105 | } 106 | 107 | if(isInTree(t, 15)) { /* Verifica se o número 15 pertence a árvore */ 108 | printf("\nO numero 15 pertence a arvore!\n"); 109 | } else { 110 | printf("\nO numero 15 NAO pertence a arvore!\n"); 111 | } 112 | 113 | if(isInTree(t, 22)) { /* Verifica se o número 22 pertence a árvore */ 114 | printf("\nO numero 22 pertence a arvore!\n\n"); 115 | } else { 116 | printf("\nO numero 22 NAO pertence a arvore!\n\n"); 117 | } 118 | 119 | free(t); /* Libera a memória alocada pela estrutura árvore */ 120 | 121 | return 0; 122 | } -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/AlunosMatriz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/AlunosMatriz -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/AlunosMatriz.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | Ler as notas de 3 provas de todos alunos de uma turma (são 10 alunos) e armazenar 4 | numa matriz onde cada linha representa um aluno e cada coluna uma prova. Calcular a 5 | nota media de cada aluno e a nota média de cada prova. Apresentar os resultados. 6 | 7 | *******************************************************************************/ 8 | #include 9 | #include 10 | 11 | #define NOTAS 4 12 | #define ALUNOS 11 13 | int main(){ 14 | 15 | float Sala[ALUNOS][NOTAS]; 16 | printf("\n"); 17 | for( int i = 0; i < ALUNOS-1; i++){ 18 | float aux=0; 19 | //float aux2 =0; 20 | for(int j = 0; j < NOTAS-1; j++){ 21 | Sala[i][j] = 9 /*(float)(rand()%11)*/; 22 | aux+=Sala[i][j]; 23 | //aux2+=Sala[10][j]; 24 | //Sala[10][j]= aux2/9; 25 | } 26 | 27 | Sala[i][3]= aux/3; 28 | 29 | } 30 | 31 | float mediaNotas[9]; 32 | for( int j = 0; j < NOTAS-1; j++){ 33 | float aux3=0; 34 | 35 | for(int i = 0; i < ALUNOS-1; i++){ 36 | aux3 += Sala[i][j]; 37 | mediaNotas[i] = aux3; 38 | } 39 | 40 | 41 | } 42 | 43 | for( int i = 0; i < ALUNOS-1; i++){ 44 | printf(" Aluno %d: ", i+1); 45 | for(int j = 0; j < NOTAS; j++){ 46 | printf(" %.1f",Sala[i][j]); 47 | } 48 | printf(" Média das Provas: %.1f", mediaNotas[i]); 49 | printf("\n"); 50 | } 51 | 52 | 53 | 54 | return 0; 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Caminhada: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/Caminhada -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Caminhada.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int inteiroResto(int num1, int num2, int *result, int *divi){ 4 | 5 | if(num1 > num2){ 6 | *result = num1 / num2; 7 | *divi = num1 % num2; 8 | } 9 | else{ 10 | *result = num2 / num1; 11 | *divi = num2 % num1; 12 | } 13 | } 14 | 15 | int main(){ 16 | 17 | int num1, num2, result, divi; 18 | 19 | printf("Digite dois numeros: "); 20 | scanf("%d %d",&num1, &num2); 21 | inteiroResto(num1, num2, &result, &divi); 22 | printf("Resultado divisao: %d\nResto divisao: %d \n", result, divi); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Conversor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/Conversor -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Conversor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int converterReal(char option, int valor, float *resultado){ 4 | system("clear"); 5 | *resultado = 0; 6 | if(option == 'E'){ 7 | *resultado = valor * 0.1807828; 8 | } 9 | else if(option == 'D'){ 10 | *resultado = valor * 0.1953011; 11 | } 12 | system("clear"); 13 | } 14 | 15 | int converterDolar(char option, int valor, float *resultado){ 16 | *resultado = 0; 17 | if(option == 'E'){ 18 | *resultado = valor * 0.9256688; 19 | } 20 | else if(option == 'R'){ 21 | *resultado = valor * 5.1197; 22 | } 23 | system("clear"); 24 | } 25 | 26 | int converterEuro(char option, int valor, float *resultado){ 27 | *resultado = 0; 28 | if(option == 'D'){ 29 | *resultado = valor * 1.0803; 30 | } 31 | else if(option == 'R'){ 32 | *resultado = valor * 5.5288; 33 | } 34 | 35 | system("clear"); 36 | } 37 | 38 | int main(){ 39 | 40 | float resultado; 41 | int valor; 42 | char option; 43 | do{ 44 | 45 | printf("Escolha uma moeda para converter\n[R] = REAL\n[D] = DOLAR\n[E] = EURO\n\n"); 46 | scanf("%s",&option); 47 | printf("Digite o valor que deseja converter: "); 48 | scanf("%d", &valor); 49 | system("clear"); 50 | switch(option){ 51 | case 'E': 52 | printf("Digite a moeda que voce deseja converter para:\n[D] DOLAR\n[R] REAL\n\n"); 53 | scanf("%s",&option); 54 | converterEuro(option, valor, &resultado); 55 | printf("VALOR CONVERTIDO: %f\n", resultado); 56 | break; 57 | case 'R': 58 | printf("Digite a moeda que voce deseja converter para:\n[E] EURO\n[D] DOLAR\n\n"); 59 | scanf("%s",&option); 60 | converterReal(option, valor, &resultado); 61 | printf("VALOR CONVERTIDO: %f\n", resultado); 62 | break; 63 | case 'D': 64 | printf("Digite a moeda que voce deseja converter para:\n[E] EURO\n[R] REAL\n\n"); 65 | scanf("%s",&option); 66 | converterDolar(option, valor, &resultado); 67 | printf("VALOR CONVERTIDO: %f\n", resultado); 68 | break; 69 | default: 70 | printf("Invalid option\n"); 71 | break; 72 | } 73 | }while(option != 'P'); 74 | 75 | return 0; 76 | } -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Ordena: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/Ordena -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Ordena.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define N 5 7 | /* 8 | 9 | Cria um vetor de 1000 elementos 10 | Preencher com numeros aleatorios 11 | Chamar a função pesquisa linear; 12 | 13 | */ 14 | 15 | int bubbleSortRec(int *V, int tam){ 16 | int aux, swap = 0; 17 | for (int i = 0; i < tam - 1; i++) { 18 | if (V[i] > V[i + 1]) { 19 | aux = V[i]; 20 | V[i] = V[i + 1]; 21 | V[i + 1] = aux; 22 | swap = 1; 23 | } 24 | if (swap != 0 && tam > 1) 25 | bubbleSortRec(V, tam - 1); 26 | } 27 | } 28 | 29 | int bubbleSortRecInv(int *V, int tam) { 30 | int aux, swap = 0; 31 | for (int i = 0; i < tam - 1; i++) { 32 | if (V[i] < V[i + 1]) { 33 | aux = V[i]; 34 | V[i] = V[i + 1]; 35 | V[i + 1] = aux; 36 | swap = 1; 37 | } 38 | if (swap != 0 && tam > 1) 39 | bubbleSortRecInv(V, tam - 1); 40 | } 41 | } 42 | 43 | 44 | void verifica(int *V){ 45 | 46 | int i=0; 47 | 48 | if(V[i]>V[N]){ 49 | printf("\nVetor em Ordem Decrescente. "); 50 | } 51 | else if(V[i] 0) { 68 | printf("O número %d foi encontrado %d vezes.", num, cont); 69 | } 70 | else{ 71 | printf("O número %d não foi encontrado.", num); 72 | } 73 | } 74 | 75 | int main() { 76 | setlocale(LC_ALL, "Portuguese"); 77 | srand(time(NULL)); 78 | int tam = N; 79 | int num, opc; 80 | int *V; 81 | V = malloc(sizeof(int) * N); 82 | printf("\nVetor aleatório não ordenado: [ "); 83 | for (int i = 0; i < N; i++) { 84 | V[i] = rand() % N; 85 | printf("%d ", V[i]); 86 | } 87 | printf("]\n"); 88 | bubbleSortRec(V, tam); 89 | printf("Vetor Ordenado: [ "); 90 | for (int i = 0; i < N; i++) { 91 | printf("%d ", V[i]); 92 | } 93 | printf("]"); 94 | 95 | verifica(V); 96 | 97 | bubbleSortRecInv(V, tam); 98 | printf("\nVetor Ordenado Invertido: [ "); 99 | for (int i = 0; i < N; i++) { 100 | printf("%d ", V[i]); 101 | } 102 | printf("]"); 103 | 104 | verifica(V); 105 | 106 | do{ 107 | 108 | printf("\nDigite o número a ser encontrado: "); 109 | scanf("%d", &num); 110 | pesquisaLinear(V, num); 111 | printf("\nDeseja continuar testando (1)Continua|(0)Para: "); 112 | scanf("%d", &opc); 113 | 114 | }while (opc != 0); 115 | 116 | free(V); 117 | 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/ProcurarElemento: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/ProcurarElemento -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/ProcurarElemento.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | Ler 9 números inteiros para preencher uma matriz D 3x3, ou seja, com 3 linhas e 3 4 | colunas. A seguir, ler um número inteiro X e escrever uma mensagem indicando se o valor 5 | de X existe ou não na matriz D. E, se existir, quantas vezes foi encontrado. 6 | 7 | *******************************************************************************/ 8 | #include 9 | #include 10 | 11 | int main(){ 12 | 13 | 14 | int M[3][3]; 15 | int cont =0; 16 | 17 | int valor; 18 | 19 | printf("\nInsira o valor pra ver se existe: "); 20 | scanf("%d",&valor); 21 | 22 | for(int i=0;i<3;i++){ 23 | for(int j=0;j<3;j++){ 24 | M[i][j] = rand()%11; 25 | if(valor == M[i][j]){ 26 | cont++; 27 | } 28 | } 29 | } 30 | 31 | 32 | printf("\nQtde de vezes que ele aparece: %d ", cont); 33 | 34 | 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/Tiro.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define pi 3.1415 5 | 6 | 7 | int main (){ 8 | 9 | float areaCirculo, areaRetangulo, raio,largura,comprimento, menorlado; 10 | 11 | printf("\nDigite o valor do raio: "); 12 | scanf("%f",&raio); 13 | 14 | printf("\nDigite o valor do largura: "); 15 | scanf("%f",&largura); 16 | 17 | printf("\nDigite o valor do comprimento: "); 18 | scanf("%f",&comprimento); 19 | 20 | areaCirculo = pi * pow(raio,2); 21 | areaRetangulo = largura*comprimento; 22 | 23 | printf("\nA área do círculo é %f", areaCirculo); 24 | 25 | if(largura == comprimento){ 26 | printf("\nÉ um quadrado."); 27 | printf("\nA área do quadrado é %f", areaRetangulo); 28 | if(largura >= 2*raio){ 29 | printf("\nO círculo cabe dentro do quadrado. "); 30 | } 31 | else{ 32 | printf("\nO círculo não cabe dentro do quadrado."); 33 | } 34 | } 35 | else{ 36 | printf("\nÉ um retângulo."); 37 | printf("\nA área do retângulo é %f", areaRetangulo); 38 | 39 | if(largura > comprimento){ 40 | menorlado = largura; 41 | } 42 | else{ 43 | menorlado = comprimento; 44 | } 45 | 46 | if(raio <= menorlado){ 47 | printf("\nO círculo cabe dentro do retângulo. "); 48 | } 49 | else(raio > menorlado){ 50 | printf("\nO círculo não cabe dentro do retângulo. "); 51 | } 52 | } 53 | 54 | 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/VetorOrdInv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/VetorOrdInv -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/VetorOrdInv.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | Ler um vetor V de 10 elementos. Criar um vetor I, com todos os elementos de V na 4 | ordem inversa, ou seja, o último elemento passará a ser o primeiro, o penúltimo será o 5 | segundo e assim por diante. Escrever todo o vetor V e todo o vetor I. 6 | → Um For para receber os dados e outro para imprimir. 7 | 8 | *******************************************************************************/ 9 | #include 10 | #define TAM 10 11 | int main() 12 | { 13 | 14 | int V[TAM]; 15 | int I[TAM]; 16 | 17 | for (int i = 0; i < TAM; i++){ 18 | V[i] = i; 19 | I[TAM -1-i] = V[i]; 20 | } 21 | 22 | for( int i = 0; i< TAM; i++){ 23 | printf("\n| V: %d | I: %d |", V[i], I[i]); 24 | } 25 | printf("\n"); 26 | 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/calculaCirculo.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 1. Implemente a função calculaCirculo, a qual calcula a área e a circunferência de um círculo de 4 | raio r. Essa função deve obedecer o protótipo: 5 | void calculaCirculo(float r, float * circunferencia, float * area); 6 | Fórmulas: 7 | A = π r^2; 8 | c = 2 π r; 9 | π = 3.14159265; 10 | 11 | Note que essa passagem dos 2 últimos parâmetros é uma passagem por referência. 12 | Tá fácil? Então faça uma “calculaQuadrilátero” também! 13 | 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define PI 3.14159265 21 | 22 | void calculaCirculo(float r, float *circunferencia, float *area){ 23 | *area = PI*pow(r,2); 24 | *circunferencia = 2*PI*r; 25 | 26 | printf("\nA area do circulo: %.2f | E sua circunferencia: %.2f ", *area, *circunferencia); 27 | } 28 | void main(){ 29 | 30 | float r; 31 | float area ,circunferencia; 32 | 33 | 34 | printf("\nDigite o valor do raio: "); 35 | scanf("%f", &r); 36 | calculaCirculo(r, &circunferencia, &area); 37 | 38 | 39 | } -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/concatString.c: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | 4 | Welcome to GDB Online. 5 | GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, 6 | C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. 7 | Code, Compile, Run and Debug online from anywhere in world. 8 | 9 | *******************************************************************************/ 10 | #include 11 | #include 12 | 13 | int main() { 14 | char string1[20] = "Hello"; 15 | char string2[20] = "World"; 16 | char string3[40]; 17 | strcpy(string3, string1); 18 | strcat(string3, " "); 19 | strcat(string3, string2); 20 | printf("%s", string3); 21 | return 0; 22 | } 23 | /* 24 | #include 25 | 26 | void concatenate(char string1[], char string2[], char result[]) { 27 | int i, j; 28 | for (i = 0; string1[i] != '\0'; i++) { 29 | result[i] = string1[i]; 30 | } 31 | for (j = 0; string2[j] != '\0'; j++) { 32 | result[i + j] = string2[j]; 33 | } 34 | result[i + j] = '\0'; 35 | } 36 | 37 | int main() { 38 | char string1[20] = "Hello"; 39 | char string2[20] = "World"; 40 | char result[40]; 41 | concatenate(string1, string2, result); 42 | printf("%s", result); 43 | return 0; 44 | } 45 | 46 | */ 47 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/criptografia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Atividade Prática Prog2 Férias/criptografia -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/criptografia.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Fazer um programa para receber uma string do usuário (máx. 50 caracteres) e fazer uma 4 | estatística dos caracteres digitados. Por exemplo, para a string "O EXERCICIO E FACIL"”, a 5 | estatística mostrada será 'O' = 2, ' '=3, 'E' = 3, 'X' = 1, 'R' = 1, 'C' = 3, 'I' = 3, 'F' = 1, 'A' = 1, 'L' = 1 6 | */ 7 | #include 8 | #include 9 | 10 | int main() { 11 | char str[51]; 12 | int i, j, len, count,aux; 13 | int frequencia[26] = {0}; // array para armazenar a frequencia de cada letra 14 | printf("Digite uma string: "); 15 | scanf("%50[^\n]",str); 16 | len = strlen(str); 17 | 18 | // loop para contar a frequencia de cada letra 19 | for(i=0; i= 'a' && str[i] <= 'z') { 21 | frequencia[str[i] - 'a']++; 22 | } else if(str[i] >= 'A' && str[i] <= 'Z') { 23 | frequencia[str[i] - 'A']++; 24 | } 25 | else if(str[i] == ' '){ 26 | aux++; 27 | 28 | } 29 | } 30 | 31 | // loop para imprimir a frequencia de cada letra 32 | for(i=0; i<26; i++) { 33 | if(frequencia[i] != 0) { 34 | printf("'%c' = %d, ", i + 'a', frequencia[i]); 35 | } 36 | } 37 | printf("Espaços em branco: %d \n", aux); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* 6 | 7 | Atividade: Alterar 8 | 9 | No exemplo que separa valores acima da média: 10 | > Função deve devolver a média para a main para que seja exibida junto aos valores > média. 11 | > Fazer na main um loop para receber a qtde de valores a serem informados, alocar o espaço para este vetor e receber os valores com scanf. 12 | 13 | 14 | */ 15 | 16 | int *obtemMaioresMedia (int *vet, int tam, int *novoTam, int *media){ 17 | int i,j,ct=0; 18 | *media=0; 19 | int *novoVet; 20 | 21 | //calcula a media 22 | for (i=0; i*media) ct++; 30 | *novoTam = ct; 31 | 32 | //aloca novo vetor 33 | novoVet = (int *) malloc(ct* sizeof(int)); 34 | 35 | //preenche com valores acima da media 36 | //printf("\nValores maior que a media: "); 37 | for (i=0, j=0; i*media) { 39 | novoVet[j]=vet[i]; 40 | j++; 41 | } 42 | // retorna o vetor com valores acima da media 43 | return novoVet; 44 | } 45 | 46 | 47 | 48 | void main () { 49 | 50 | int tamNovo, i; 51 | 52 | int vetor [10]; 53 | printf("\nVetor primario: "); 54 | for(int i = 0; i < 10; i++){ 55 | vetor[i] = rand()%11; 56 | printf("%d ", vetor[i]); 57 | } 58 | int *vetMaioresMedia; 59 | 60 | vetMaioresMedia = obtemMaioresMedia (vetor, 10, &tamNovo); 61 | 62 | for (i=0; i 2 | #include 3 | #include 4 | 5 | #define TAM 10 6 | 7 | *obtemMaiorMedia(int *V, int *novoTam, int *media){ 8 | 9 | *media = 0; 10 | 11 | //Calculando a média. 12 | for(int i=0; i< TAM; i++){ 13 | *media += V[i]; 14 | } 15 | *media/=TAM; 16 | 17 | //Acima da média. 18 | 19 | } 20 | 21 | void main(){ 22 | 23 | int tamNovo; 24 | 25 | int V[TAM]; 26 | printf("\nVetor Primário: > "); 27 | for (int i=0; i 28 | #include 29 | #include 30 | 31 | int *premiados(int n, int *inscr, float *t1, int p1, float *t2, int p2, int *tam) { 32 | float max_media = -1; // inicializa com valor menor possível 33 | int *inscr_premiados = NULL; // cria vetor vazio 34 | int cont = 0; // contador para o tamanho do vetor inscr_premiados 35 | 36 | // loop para calcular a média ponderada e verificar se é a maior 37 | for (int i = 0; i < n; i++) { 38 | float media = (t1[i] * p1 + t2[i] * p2) / (p1 + p2); // calcula a média ponderada 39 | if (media > max_media) { // verifica se é a maior 40 | max_media = media; // atualiza a maior média 41 | cont = 1; // reinicia o contador 42 | if (inscr_premiados) free(inscr_premiados); // libera memória alocada anteriormente 43 | inscr_premiados = (int *)malloc(sizeof(int)); // aloca memória para um inteiro 44 | inscr_premiados[0] = inscr[i]; // armazena a inscrição do participante 45 | } else if (media == max_media) { // verifica se é igual à maior 46 | cont++; // incrementa o contador 47 | inscr_premiados = (int *)realloc(inscr_premiados, cont * sizeof(int)); // aloca mais memória 48 | inscr_premiados[cont-1] = inscr[i]; // armazena a inscrição do participante 49 | } 50 | } 51 | *tam = cont; // armazena o tamanho do vetor inscr_premiados 52 | return inscr_premiados; // retorna o ponteiro para o vetor inscr_premiados 53 | } 54 | 55 | 56 | 57 | int main() { 58 | int n; 59 | printf("Número dos participantes: "); 60 | scanf("%d", &n); 61 | int inscr[n]; 62 | float t1[n], t2[n]; 63 | int p1, p2, tam; 64 | 65 | // loop para ler as informações dos participantes 66 | for (int i = 0; i < n; i++) { 67 | printf("Digite o número de inscrição do participante %d: ", i+1); 68 | scanf("%d", &inscr[i]); 69 | printf("Digite a nota do participante %d na P1: ", i+1); 70 | scanf("%f", &t1[i]); 71 | printf("Digite a nota do participante %d na P1: ", i+1); 72 | scanf("%f", &t2[i]); 73 | } 74 | printf("Digite o peso da P1: "); 75 | scanf("%d", &p1); 76 | printf("Digite o peso da P2: "); 77 | scanf("%d", &p2); 78 | 79 | for(int i = 0; i < n; i++){ 80 | printf("Participante de inscrição %.2d: Notas: %.2f | %.2f\n",i+1,t1[i],t2[i]); 81 | } 82 | 83 | int *inscr_premiados = premiados(n, &inscr, &t1, p1, &t2, p2, &tam); 84 | printf("\nAs inscrições vencedoras são: "); 85 | for (int i = 0; i < tam; i++) { 86 | printf("%d \n", inscr_premiados[i]); 87 | } 88 | printf("\n"); 89 | free(inscr_premiados); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /FACULDADE/Atividade Prática Prog2 Férias/taximetro.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Desde março deste ano, os 33 táxis da cidade de Rio das Ostras tiveram que instalar a aferir 4 | taxímetros para o cálculo do valor das corridas. De acordo com a tabela em vigor, a tarifa inicial 5 | (ou bandeirada) custa R$4,95. Além disso, para cada quilômetro percorrido são cobrados mais 6 | R$2,50, na bandeira 1, ou R$3,00, na bandeira 2. 7 | Escreva uma função em C que calcula os valores da corrida de táxi em Rio das Ostras. 8 | A função recebe como parâmetros o valor real dist,correspondendo à distância percorrida 9 | pelo táxi (em quilômetros), e os ponteiros b1 e b2, indicando os endereços onde devem ser armazenados, 10 | respectivamente, os valores calculados para a corrida na bandeira 1 e na bandeira 2. 11 | 12 | void calcula_corrida(float dist, float *b1, float *b2); 13 | 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define tarifa 4.95 21 | 22 | void calcula_corrida(float dist, float *b1, float *b2){ 23 | 24 | float precob1, precob2 = 0; 25 | precob1 = tarifa + (dist*(*b1)); 26 | precob2 = tarifa + (dist*(*b2)); 27 | 28 | printf("\nO preco pela Bandeira 1: %.2f reais e pela Bandeira 2: %.2f reais", precob1, precob2); 29 | 30 | } 31 | 32 | void main(){ 33 | 34 | float dist; 35 | float b1 = 2.5; 36 | float b2 = 3; 37 | 38 | printf("\nQual a distancia percorrida: "); 39 | scanf("%f", &dist); 40 | calcula_corrida(dist, &b1, &b2); 41 | 42 | } -------------------------------------------------------------------------------- /FACULDADE/Lista Encadeada/lista: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Lista Encadeada/lista -------------------------------------------------------------------------------- /FACULDADE/Lista Encadeada/lista.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Criação de uma lista, usando struct. 6 | 7 | struct lista { 8 | struct lista *next; 9 | int info; 10 | }; 11 | typedef struct lista Lst; 12 | 13 | // Função que gera lista vazia. 14 | 15 | Lst *lstCreate(){ 16 | return NULL; // Ela gera e seta a lista como vazia. 17 | } 18 | 19 | Lst *lstInsert(Lst* l, int i){ 20 | Lst* novo = (Lst*)malloc(sizeof(Lst)); 21 | novo->info = i; 22 | novo->next = l; 23 | printf("Número inserido com sucesso. \n"); 24 | return novo; 25 | } 26 | 27 | // Função que mostra a minha lista. 28 | 29 | void lstPrint(Lst* l){ 30 | Lst* p; 31 | printf("Lista ["); 32 | for(p = l; p != NULL; p = p->next){ 33 | printf(" %d ", p->info); 34 | } 35 | printf("]"); 36 | } 37 | 38 | // Libera a memória alocada da lista. 39 | 40 | void lstFree(Lst* l){ 41 | Lst* p = l; 42 | while(p!= NULL){ 43 | Lst* t = p->next; // Guarda referência para next elemento. 44 | free(p); // Libera a memória apontada por p. 45 | p=t; // Faz p apontar pro next. 46 | } 47 | } 48 | 49 | // Função que busca algum elemento da minha lista. 50 | 51 | Lst* lstSearch(Lst* l, int s){ 52 | Lst* p; 53 | for(p = l; p!= NULL; p = p->next){ 54 | if(p->info == s) 55 | return p; 56 | } 57 | return NULL; 58 | } 59 | 60 | // Função que retira algum elemento da lista, caso exista. 61 | 62 | Lst* lstDelete(Lst* l, int d){ 63 | Lst* ant = NULL; // Aponta pro anterior. 64 | Lst* p = l; // Aponta pra percorrer a lista. 65 | 66 | // Verificação se existe esse elemento. 67 | while(p != NULL && p-> info != d){ 68 | ant = p; 69 | p = p-> next; 70 | } 71 | // Verifica se achou elemento 72 | if(p == NULL){ 73 | return l; // Caso não ache, retorna a lista. 74 | } 75 | // Retira elemento. 76 | if(ant == NULL){ 77 | // Retira do início. 78 | l = p->next; 79 | } 80 | else{ 81 | // Retira elemento do meio da lista. 82 | ant-> next = p->next; 83 | } 84 | free(p); 85 | return l; 86 | } 87 | int main(){ 88 | setlocale(LC_ALL,""); 89 | int opc; 90 | 91 | Lst* l; // Declara a lista vazia, 92 | l = lstCreate(); // Inicia a lista vazia. 93 | 94 | do{ 95 | printf("\nInsira a opção adequada para o que deseja: \n"); 96 | printf("[1] Para inserir na lista.\n[2] Para exibir a lista.\n[3] Para buscar um elemento.\n[4] Para Excluir um elemento.\n[0] Para finalizar a lista.\n"); 97 | printf("Opção desejada: "); 98 | scanf("%d", &opc); 99 | 100 | switch(opc){ 101 | case 1: 102 | int i; 103 | printf("Insira o num: "); 104 | scanf("%d", &i); 105 | l = lstInsert(l,i); 106 | break; 107 | case 2: 108 | lstPrint(l); 109 | break; 110 | case 3: 111 | int s; 112 | printf("Insira o num: "); 113 | scanf("%d", &s); 114 | l = lstSearch(l,s); 115 | break; 116 | case 4: 117 | int d; 118 | printf("Insira o num: "); 119 | scanf("%d", &d); 120 | l = lstDelete(l,d); 121 | break; 122 | case 0: 123 | lstFree(l); 124 | printf ("Lista finalizada com sucesso!\n"); 125 | break; 126 | default: 127 | printf("Opc não consta. \n"); 128 | break; 129 | 130 | 131 | system("clear"); 132 | system("cls"); 133 | } 134 | }while(opc != 0); 135 | return 0; 136 | } 137 | -------------------------------------------------------------------------------- /FACULDADE/Lista Encadeada/listaSimpEcad.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define lim 100 6 | 7 | typedef struct lista{ 8 | int info; 9 | struct lista *prox; 10 | }Lista; 11 | 12 | Lista* inserir(Lista *L, int x){ 13 | Lista* pt=NULL; 14 | 15 | pt=(Lista*)malloc(sizeof(Lista)); 16 | pt->prox=L; 17 | pt->info=x; 18 | return pt; 19 | } 20 | 21 | void imprimir(Lista *L){ 22 | Lista* pt=L; 23 | 24 | printf("L = "); 25 | while(pt!=NULL){ 26 | printf("%d ",pt->info); 27 | pt=pt->prox; 28 | } 29 | } 30 | 31 | void preOrdem(Lista *L){ 32 | 33 | if(L!=NULL){ 34 | printf("%d ",L->info); 35 | preOrdem(L->prox); 36 | } 37 | } 38 | 39 | void posOrdem(Lista *L){ 40 | 41 | if(L!=NULL){ 42 | posOrdem(L->prox); 43 | printf("%d ",L->info); 44 | } 45 | } 46 | 47 | 48 | int main(){ 49 | 50 | Lista* L=NULL; 51 | int tam; 52 | 53 | printf("Digite o tamanho da lista: "); 54 | scanf("%d", &tam); 55 | srand(time(NULL)); 56 | for(int i=0;i 2 | #include "lst_encad.c" 3 | 4 | int main(){ 5 | 6 | 7 | Lista* l; // Declara a lista vazia, 8 | l = lstCria(); // Inicia a lista vazia. 9 | l = lstInsere(l,10); 10 | l = lstInsere(l,20); 11 | l = lstInsere(l,30); 12 | lstPrint(l); 13 | l = lstRetira(l,11); 14 | l = lstRetira(l,20); 15 | lstPrint(l); 16 | lstLibera(l); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /FACULDADE/Lista Encadeada/lst_encad.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Criação de Lista. 5 | 6 | struct lista{ 7 | int info; 8 | struct lista *prox; 9 | 10 | }; 11 | typedef struct lista Lista; 12 | 13 | // Função de Criação. 14 | // Retorna lista vazia. 15 | 16 | Lista *lstCria(void){ 17 | return NULL; 18 | } 19 | 20 | // Insere na Lista. 21 | //Retorna lista atualizada. 22 | 23 | Lista* lstInsere(Lista* l, int i){ 24 | Lista* novo = (Lista*) malloc(sizeof(Lista)); 25 | novo->info = i; 26 | novo->prox = l; 27 | return novo; 28 | } 29 | 30 | /* 31 | Lista* lstInsereDP(Lista **l , int i){ 32 | 33 | Lista* novo = (Lista*) malloc(sizeof(Lista)); 34 | novo->info = i; 35 | novo->prox = *l; 36 | *l = novo; 37 | return novo; 38 | } 39 | */ 40 | // Função que percorre a lista e mostra os itens. 41 | 42 | void lstPrint(Lista* l){ 43 | 44 | Lista *p; // Variável pra percorrer a lista. 45 | for(p=l;p!=NULL;p=p->prox){ 46 | printf("info =%d \n",p->info); 47 | } 48 | } 49 | 50 | // Verifica se a função é vazia. 51 | 52 | int lstVazia(Lista* l){ 53 | /*if( l == NULL){ 54 | return 1; // Retorna 1 se é vazia. 55 | } 56 | else 57 | return 0;*/ 58 | 59 | // Outro modo de escrever. 60 | return ( l == NULL); 61 | } 62 | 63 | // Função que busca um elemento da lista. 64 | 65 | Lista* lstBusca(Lista* l, int v){ 66 | Lista* p; 67 | for(p=l;p!=NULL;p=p->prox){ 68 | if(p->info == v){ 69 | return p; 70 | } 71 | return NULL; // Caso não ache o elemento. 72 | } 73 | } 74 | 75 | // Função que retira um elemento da lista, caso exista. 76 | 77 | Lista* lstRetira(Lista* l, int v){ 78 | Lista* ant = NULL; // Pointer pro elemento anterior. 79 | Lista* p = l; // Pointer pra percorrer a lista. 80 | 81 | // Procura um elemento na lista, guardando o anterior. 82 | while(p != NULL && p-> info != v){ 83 | ant = p; 84 | p = p-> prox; 85 | } 86 | // Verifica se achou elemento 87 | if(p == NULL){ 88 | return l; // Caso não ache, retorna a lista. 89 | } 90 | // Retira elemento. 91 | if(ant == NULL){ 92 | // Retira do início. 93 | l = p->prox; 94 | } 95 | else{ 96 | // Retira elemento do meio da lista. 97 | ant-> prox = p->prox; 98 | } 99 | free(p); 100 | return l; 101 | 102 | } 103 | 104 | // Libera a lista. 105 | 106 | void lstLibera(Lista* l){ 107 | Lista* p = l; 108 | while(p!= NULL){ 109 | Lista* t = p->prox; // Guarda referência para prox elemento. 110 | free(p); // Libera a memória apontada por p. 111 | p=t; // Faz p apontar pro prox. 112 | } 113 | } 114 | /* 115 | // TAD: Lista de inteiros. 116 | 117 | typedef struct lista Lista; 118 | 119 | Lista* lstCria(void); 120 | void lstLibera(Lista* l); 121 | 122 | Lista* lstInsere(Lista* l, int i); 123 | Lista* lstRetira(Lista* l, int v); 124 | 125 | int lstVazia(Lista* l); 126 | Lista* lstBusca(Lista* l,int v); 127 | void lstPrint(Lista* l); 128 | */ 129 | // Função Insere um elemento em ordem. 130 | 131 | Lista* lstInsereOrd(Lista* l, int v){ 132 | 133 | Lista* novo; 134 | Lista* ant = NULL; 135 | Lista* p = l; 136 | 137 | // Procura posição de Inserção. 138 | 139 | while(p!= NULL && p->info < v){ 140 | 141 | ant = p; 142 | p = p->prox; 143 | } 144 | 145 | // Cria novo elemento. 146 | 147 | novo = (Lista*) malloc(sizeof(Lista)); 148 | novo->info = v; 149 | 150 | // Encadeia elemento. 151 | 152 | if(ant == NULL){ 153 | 154 | novo->prox = l; 155 | l = novo; 156 | 157 | } 158 | else{ 159 | novo->prox = ant; 160 | ant->prox = novo; 161 | } 162 | 163 | return l; 164 | } -------------------------------------------------------------------------------- /FACULDADE/Ponteiros/ponteiro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Ponteiros/ponteiro -------------------------------------------------------------------------------- /FACULDADE/Ponteiros/ponteiro.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //void troca(int *px, int *py) 4 | //{ 5 | // 6 | //int t; 7 | //t = *px; // t recebe o conteúdo de x 8 | //*px = *py; // x recebe o conteúdo de y 9 | //*py = t; // y recebe o conteúdo de x 10 | // 11 | //} 12 | // 13 | //void main() 14 | //{ 15 | // 16 | //int x, y; 17 | //printf ("Informe as coordenadas:"); 18 | //scanf("%d %d",&x, &y); 19 | //printf("Antes da troca - X: %d Y: %d \n", x, y); 20 | //troca(&x, &y); 21 | //printf("Depois da troca - X: %d Y: %d \n", x, y); 22 | // 23 | // 24 | //int *p1,**p2,***p3, var; //variável int e ponteiros para a variável int 25 | //var = 97; 26 | //p1 = &var; //ponteiro 1 recebe o endereço de var 27 | //p2 = &p1; //ponteiro 2 recebe o endereço de ponteiro 1 28 | //p3 = &p2; //ponteiro 3 recebe o endereço de ponteiro 2 29 | //printf("\nEndereço da Var %p", &var); 30 | //printf("\nEndereço do ponteiro 1: %p",&p1); 31 | //printf("\nEndereço do ponteiro 2: %p",&p2); 32 | //printf("\nEndereço do ponteiro 3: %p",&p3); 33 | //printf("\nEndereço apontado pelo ponteiro 1: %p",p1); 34 | //printf("\nEndereço apontado pelo ponteiro 2: %p",p2); 35 | //printf("\nEndereço apontado pelo ponteiro 3: %p",p3); 36 | //printf("\nConteúdo de Var:%d",var); 37 | //printf("\nConteúdo de Var pelo ponteiro 1:%d",*p1); 38 | //printf("\nConteúdo de Var pelo ponteiro 2:%d",**p2); 39 | //printf("\nConteúdo de Var pelo ponteiro 3:%d",***p3); 40 | 41 | //int *p1, var; 42 | //var = 65; 43 | //p1 = &var; 44 | //printf("\nEndereço da Var %p", &var); 45 | //printf("\nEndereço apontado pelo ponteiro 1: %p",p1); 46 | //p1++; 47 | //printf("\n ( p + 1): %p",p1); 48 | //p1--; 49 | //printf("\n ( p -1 ): %p",p1); 50 | //printf("\nConteúdo de Var pelo ponteiro 1:%d \n",*p1); 51 | 52 | //int i; 53 | //int *p0 = &i; 54 | //int *p1 = &i + 1; 55 | //int *p2 = &i + 2; 56 | //int *p3 = p2; 57 | //printf("p2 > p0: %d\n", p2 > p0); 58 | //printf("p0 > p1: %d\n", p0 > p1); 59 | //printf("p2 < p0: %d\n", p2 < p0); 60 | //printf("p3 = p2: %d\n", p3 == p2); 61 | //return 0; 62 | 63 | //********************** Recursividade 64 | 65 | //int fat_rec(int i) { 66 | // if (i==0) 67 | // return(1); 68 | // else 69 | // return (i * fat_rec (i-1)); 70 | //} 71 | // 72 | //void main() { 73 | // int n, f; 74 | // printf ("\n Digite um número inteiro:"); 75 | // scanf("%d",&n); 76 | // if (n<=0) 77 | // f = 1; 78 | // else 79 | // f=fat_rec(n); 80 | // printf ("Fatorial de %d é %d", n, f); 81 | //} 82 | // 83 | 84 | //********************* MDC recursiva 85 | #include 86 | int mdc (int x, int y) { 87 | int r =x%y; 88 | if (r==0) 89 | return y; 90 | else 91 | return mdc(y, r); 92 | } 93 | void main (void){ 94 | printf("MDC: %d",mdc(24,6)); 95 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Atividade pratica1/coralperfeito.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N; 6 | 7 | while (scanf("%d", &N) != EOF) { 8 | int i, nota[10000], som = 0; 9 | 10 | for (i = 0; i < N; ++i) { 11 | scanf("%d", ¬a[i]); 12 | som += nota[i]; 13 | } 14 | 15 | if (som % N) 16 | puts("-1"); 17 | else { 18 | int avg = som / N; 19 | int somdif = 0; 20 | 21 | for (i = 0; i < N; ++i) 22 | if (nota[i] > avg) 23 | somdif += nota[i] - avg; 24 | 25 | printf("%d\n", somdif + 1); 26 | } 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Atividade pratica1/coralperfeito.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Atividade pratica1/coralperfeito.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Atividade pratica1/fatorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int fatorialRecursivo(int numero){ 7 | 8 | if(numero==0) return 1; 9 | if(numero==1) return numero*fatorialRecursivo(numero-1); 10 | } 11 | 12 | int fatorial(int numero){ 13 | 14 | printf("Numero: %d\n",numero); 15 | int fat=1; 16 | while (numero != 0) { 17 | fat *= numero; 18 | numero--; 19 | } 20 | 21 | printf("Fat = %d\n",fat); 22 | return fat; 23 | } 24 | 25 | int main(int numero, int fat){ 26 | 27 | setlocale(LC_ALL, " "); 28 | printf("Bem vindo ao Fatoriando...\n"); 29 | printf("Insira um numero para ser transcrito para seu fatorial: "); 30 | scanf("%d", &numero); 31 | printf("\nResultado de %d! eh: %d", numero,fatorial(numero)); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Atividade pratica1/fatorial.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Atividade pratica1/fatorial.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista Struct/lst.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Lista Struct/lst.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista Struct/struct(funcao).c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct ficha_aluno 4 | { 5 | char nome[50]; 6 | char materia[50]; 7 | float p1; 8 | float p2; 9 | // float media; 10 | float vs; 11 | }ficha; 12 | 13 | 14 | void cadastro(ficha aluno[]) 15 | { 16 | for(int pos=0; pos<2; pos++) 17 | { 18 | printf("\nNome: "); 19 | fflush(stdin); 20 | fgets(aluno[pos].nome, 50, stdin); 21 | 22 | printf("\nDisciplina: "); 23 | fflush(stdin); 24 | fgets(aluno[pos].materia, 50, stdin); 25 | 26 | printf("\nP1: "); 27 | scanf("%f", &aluno[pos].p1); 28 | if(aluno[pos].p1<0 && aluno[pos].p1>10) 29 | { 30 | printf("\n Valor incorreto de p1, insira novamente: "); 31 | printf("\nP1: "); 32 | scanf("%f", &aluno[pos].p1); 33 | } 34 | //verifica(token); 35 | 36 | printf("\nP2: "); 37 | scanf("%f", &aluno[pos].p2); 38 | if(aluno[pos].p2<0 && aluno[pos].p2>10) 39 | { 40 | printf("\n Valor incorreto de p2, insira novamente: "); 41 | printf("\nP2: "); 42 | scanf("%f", &aluno[pos].p2); 43 | } 44 | //verifica(token); 45 | 46 | //media = (aluno[pos].p1 + aluno[pos].p2)/2; 47 | } 48 | } 49 | 50 | void show(ficha aluno[]) 51 | { 52 | for(int pos=0; pos<2; pos++) 53 | { 54 | printf("\nNome: %s", aluno[pos].nome); 55 | printf("\nMateria: %s", aluno[pos].materia); 56 | printf("\nP1: %f", aluno[pos].p1); 57 | printf("\nP2: %f", aluno[pos].p2); 58 | } 59 | } 60 | 61 | 62 | 63 | int main() 64 | { 65 | ficha token[2]; 66 | printf("\nCadastro iniciado. "); 67 | cadastro(token); 68 | show(token); 69 | return 0; 70 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista Struct/struct(funcao).exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Lista Struct/struct(funcao).exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista Struct/struct(struct).c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct ficha 4 | { 5 | char nome[30]; 6 | char materia[30]; 7 | float p1,p2,media,vs; 8 | }ficha; 9 | 10 | struct ficha cad() 11 | { 12 | for(int pos=0; pos<2; pos++) 13 | { 14 | printf("\nNome: "); 15 | fflush(stdin); 16 | fgets(aluno[pos].nome, 50, stdin); 17 | 18 | printf("\nDisciplina: "); 19 | fflush(stdin); 20 | fgets(aluno[pos].materia, 50, stdin); 21 | 22 | printf("\nP1: "); 23 | scanf("%f", &aluno[pos].p1); 24 | if(aluno[pos].p1<0 && aluno[pos].p1>10) 25 | { 26 | printf("\n Valor incorreto de p1, insira novamente: "); 27 | printf("\nP1: "); 28 | scanf("%f", &aluno[pos].p1); 29 | } 30 | 31 | 32 | printf("\nP2: "); 33 | scanf("%f", &aluno[pos].p2); 34 | if(aluno[pos].p2<0 && aluno[pos].p2>10) 35 | { 36 | printf("\n Valor incorreto de p2, insira novamente: "); 37 | printf("\nP2: "); 38 | scanf("%f", &aluno[pos].p2); 39 | } 40 | media = (aluno[pos].p1 + aluno[pos].p2)/2; 41 | if(aluno.media < 6){ 42 | printf("[ATENÇÃO] O aluno deverá ter feito a VS \n"); 43 | printf("Digite a nota da AVS do aluno:\n"); 44 | scanf("%f",&aluno.vs); 45 | 46 | if(aluno.p1 2 | #include 3 | 4 | 5 | 6 | void show(int* V, int tam){ 7 | 8 | printf("V ="); 9 | for(int i=0; i 2 | 3 | void somaprod(int valor1, int valor2, int *somaP, int *produtoP){ 4 | 5 | int soma = valor1 + valor2; 6 | int produto = valor1 * valor2; 7 | *somaP = soma; 8 | *produtoP = produto; 9 | 10 | } 11 | 12 | int main(){ 13 | /* 14 | int x = 2; 15 | int *pt = &x; 16 | 17 | printf("x = %d\n", x); 18 | printf("pt = %d\n", pt); 19 | printf("*pt = %d\n", *pt); 20 | */ 21 | 22 | int valor1,valor2,soma,produto; 23 | printf("Insira valores: "); 24 | scanf("%d %d", &valor1,&valor2); 25 | printf("valor1 = %d | | valor2 = %d \n",valor1, valor2); 26 | somaprod(valor1, valor2,&soma,&produto); 27 | printf("Soma = { %d } | | Produto = { %d }",soma,produto); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista prog2/questao1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Lista prog2/questao1.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista prog2/questao3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void produtorioEsomatorio(int quantidadeNumeros,int *somatorio,int *produtorio){ 4 | int soma; 5 | int prod; 6 | int V[999]; 7 | *somatorio = soma; 8 | *produtorio = prod; 9 | int *pt = V; 10 | for (int i = 1; i <= quantidadeNumeros; i++){ 11 | V[i] = i; 12 | } 13 | for (int i = 1; i <= quantidadeNumeros; i++){ 14 | printf("V[%d", V[*pt+i]); 15 | } 16 | 17 | for(int i = 1; i <= quantidadeNumeros; i++){ 18 | *somatorio += V[i]; 19 | *produtorio *= V[i]; 20 | } 21 | } 22 | 23 | int main(){ 24 | 25 | int num,somatorio,produtorio; 26 | scanf("%d",&num); 27 | produtorioEsomatorio(num,&somatorio,&produtorio); 28 | 29 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Lista prog2/questao3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Lista prog2/questao3.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/TrabOred.c: -------------------------------------------------------------------------------- 1 | // Enuciate 2 | 3 | // Escolha um algoritmos de ordenação Alg dentre: Bolha, Inserção ou Seleção. Escolhi Bubble 4 | 5 | // Implemente 4 algoritmos de ordenação: 6 | // (i) o algoritmo Alg na versão iterativa; ok 7 | // (ii) o algoritmo Alg na versão recursiva; ok 8 | // (iii) mergesort; ok 9 | // (iv) quicksort. ok 10 | 11 | 12 | // Iniciando com n = 1000, gere 3 vetores aleatórios de tam n e execute cada um dos algoritmos medindo o tempo de execução. Some os tempos e divida por 3 para obter o tempo médio gasto por cada método. Faça o mesmo para n = 10.000, 100.000, 1.000.000 e 10.000.000. 13 | 14 | // Elabore uma tabela com os resultados. 15 | 16 | // Compare e analise o resultado de cada um dos pares de algoritmos abaixo: 17 | 18 | // a) Alg iterativo X Alg recursivo 19 | // b) Mergsort X Quicksort 20 | // c) A versão mais rápida de alg X o mais lento dentre Mergesort e Quicksort 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | void show (int *V, int N) { 28 | int i; 29 | printf("V ["); 30 | for (i=0; iV[j+1]) { 40 | aux = V[j]; 41 | V[j] = V[j+1]; 42 | V[j+1] = aux; } 43 | } 44 | 45 | void BubbleSortRecursiveSwap(int *a, int *b){ 46 | int aux = *a; 47 | *a = *b; 48 | *b = aux; 49 | } 50 | 51 | void BubbleSortRecursive(int V[],int N){ 52 | if(N==1) return; 53 | 54 | int c=0; 55 | for(int i=0;iV[i+1]){ 57 | BubbleSortRecursiveSwap(&V[i],&V[i+1]); 58 | c++; 59 | } 60 | } 61 | 62 | if(c==0) return; 63 | 64 | BubbleSortRecursive(V,N-1); 65 | } 66 | 67 | void merge(int V[], int l, int m, int r){ 68 | int i, j, k; 69 | int n1 = m - l + 1; 70 | int n2 = r - m; 71 | 72 | int VauxL[n1], VauxR[n2]; 73 | 74 | 75 | for (i = 0; i < n1; i++) 76 | VauxL[i] = V[l + i]; 77 | for (j = 0; j < n2; j++) 78 | VauxR[j] = V[m + 1 + j]; 79 | 80 | 81 | i = 0; 82 | j = 0; 83 | k = l; 84 | while (i < n1 && j < n2) { 85 | if (VauxL[i] <= VauxR[j]) { 86 | V[k] = VauxL[i]; 87 | i++; 88 | } 89 | else { 90 | V[k] = VauxR[j]; 91 | j++; 92 | } 93 | k++; 94 | } 95 | 96 | while (i < n1) { 97 | V[k] = VauxL[i]; 98 | i++; 99 | k++; 100 | } 101 | 102 | while (j < n2) { 103 | V[k] = VauxR[j]; 104 | j++; 105 | k++; 106 | } 107 | } 108 | 109 | void mergeSort(int V[], int l, int r){ 110 | 111 | if (l < r) { 112 | int m = l + (r - l) / 2; 113 | mergeSort(V, l, m); 114 | mergeSort(V, m + 1, r); 115 | merge(V, l, m, r); 116 | } 117 | } 118 | 119 | void criarvetor(int V[],int N){ 120 | srand(time(NULL)); 121 | for(int i=0; i 24 | #include 25 | #include 26 | 27 | void imprimir (int V[], int n) { 28 | int i; 29 | printf("("); 30 | for (i=0; iV[j+1]) { 40 | aux = V[j]; 41 | V[j] = V[j+1]; 42 | V[j+1] = aux; } 43 | } 44 | 45 | // ORDENAÇÃO PELO METODO BOLHA RECURSIVO 46 | void bolharec_troca(int *x, int *y){ 47 | int aux = *x; 48 | *x = *y; 49 | *y = aux; 50 | } 51 | 52 | void bolharec(int V[],int n){ 53 | 54 | if(n==1) return; 55 | 56 | int c=0; 57 | for(int i=0;iV[i+1]){ 59 | bolharec_troca(&V[i],&V[i+1]); 60 | c++; 61 | } 62 | } 63 | 64 | if(c==0) return; 65 | 66 | bolharec(V,n-1); 67 | } 68 | 69 | void mergsort(int V[],int n){ 70 | 71 | } 72 | 73 | void criarvetor(int V[],int n){ 74 | srand(time(NULL)); 75 | for(int i=0; i %f", ((double)t)/(CLOCKS_PER_SEC)); 94 | printf("\n\nTempo de execução do algoritmo Booble Sorte Recursivo -> %f", (tf-y)); 95 | //imprimir(V, n); 96 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/TrabProg2Ordenacao.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Treino de ponteiros/TrabProg2Ordenacao.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Treino de ponteiros/a.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/listaSimpEcad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Treino de ponteiros/listaSimpEcad -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/teste.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int x = 2; 7 | int *y = &x; 8 | int **z = &y; 9 | 10 | printf("x: %ld - o que y aponta: %ld - o que aponta o que z aponta:%ld\n\n",x,*y,**z); 11 | printf("x: %ld - o que y vale: %ld ( aqui eh a posicao de memoria do x, que eh o valor de y) - o que z aponta%ld (aqui z aponta para y, entao é a posicao de memoria de y)\n\n",x,y,*z); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/teste.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Treino de ponteiros/teste.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/treinoP1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Implemente uma função para cada uma das seguintes tarefas. 3 | Os parâmetros das funções estão descritos sobre uma ótica do usuário e não com o 4 | protótipo exato que será implementado. É permitido utilizar uma lista de parâmetros diferente 5 | da que foi informada. 6 | Obs1: Espaço alocado é o quanto de memória você reservou para o vetor e tamanho é o 7 | total de dados que o usuário informou. 8 | Obs2: O vetor é uma variável local da main 9 | 0) MENU: Crie um Menu recursivo que pergunta ao usuário o que ele quer fazer. Este 10 | MENU não pode ter estrutura de repetição; 11 | 1) INSERIR(x): insere um elemento x no final do vetor. Caso o vetor esteja cheio realoque 12 | o dobro do número de espaço reservado atualmente. Caso o vetor não tenha sido criado ainda, 13 | crie um com tamanho 1. 14 | 2) CONSULTAR TAMANHO: informa a quantidade de dados do vetor 15 | 3) CONSULTAR ESPAÇO ALOCADO: Informa qual o espaço de memória reservado para 16 | o vetor 17 | 4) IMPRIMIR_VETOR: imprime todos os elementos do vetor 18 | */ 19 | 20 | #include 21 | #include 22 | #include // setlocale. 23 | 24 | 25 | void mostraVetor(int *V,int tam){ 26 | 27 | printf(" Vetor ==> ");(int i=0;i 3 | #include 4 | 5 | // Merges two subarrays of arr[]. 6 | // First subarray is arr[l..m] 7 | // Second subarray is arr[m+1..r] 8 | void merge(int arr[], int l, int m, int r) 9 | { 10 | int i, j, k; 11 | int n1 = m - l + 1; 12 | int n2 = r - m; 13 | 14 | /* create temp arrays */ 15 | int L[n1], R[n2]; 16 | 17 | /* Copy data to temp arrays L[] and R[] */ 18 | for (i = 0; i < n1; i++) 19 | L[i] = arr[l + i]; 20 | for (j = 0; j < n2; j++) 21 | R[j] = arr[m + 1 + j]; 22 | 23 | /* Merge the temp arrays back into arr[l..r]*/ 24 | i = 0; // Initial index of first subarray 25 | j = 0; // Initial index of second subarray 26 | k = l; // Initial index of merged subarray 27 | while (i < n1 && j < n2) { 28 | if (L[i] <= R[j]) { 29 | arr[k] = L[i]; 30 | i++; 31 | } 32 | else { 33 | arr[k] = R[j]; 34 | j++; 35 | } 36 | k++; 37 | } 38 | 39 | /* Copy the remaining elements of L[], if there 40 | are any */ 41 | while (i < n1) { 42 | arr[k] = L[i]; 43 | i++; 44 | k++; 45 | } 46 | 47 | /* Copy the remaining elements of R[], if there 48 | are any */ 49 | while (j < n2) { 50 | arr[k] = R[j]; 51 | j++; 52 | k++; 53 | } 54 | } 55 | 56 | /* l is for left index and r is right index of the 57 | sub-array of arr to be sorted */ 58 | void mergeSort(int arr[], int l, int r) 59 | { 60 | if (l < r) { 61 | // Same as (l+r)/2, but avoids overflow for 62 | // large l and h 63 | int m = l + (r - l) / 2; 64 | 65 | // Sort first and second halves 66 | mergeSort(arr, l, m); 67 | mergeSort(arr, m + 1, r); 68 | 69 | merge(arr, l, m, r); 70 | } 71 | } 72 | 73 | /* UTILITY FUNCTIONS */ 74 | /* Function to print an array */ 75 | void printArray(int A[], int size) 76 | { 77 | int i; 78 | for (i = 0; i < size; i++) 79 | printf("%d ", A[i]); 80 | printf("\n"); 81 | } 82 | 83 | /* Driver code */ 84 | int main() 85 | { 86 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 87 | int arr_size = sizeof(arr) / sizeof(arr[0]); 88 | 89 | printf("Given array is \n"); 90 | printArray(arr, arr_size); 91 | 92 | mergeSort(arr, 0, arr_size - 1); 93 | 94 | printf("\nSorted array is \n"); 95 | printArray(arr, arr_size); 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/Treino de ponteiros/treinoP1semvoid.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/Treino de ponteiros/treinoP1semvoid.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/Fissura.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/beecrowd(merda)/Fissura.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/acidAlig.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | typedef struct item{ 6 | int chegada; 7 | int saida; 8 | struct item *prox; 9 | } Item; 10 | 11 | typedef struct pilha{ 12 | Item *topo; 13 | } Pilha; 14 | 15 | Pilha* cria_pilha(){ 16 | Pilha *p = (Pilha *) malloc(sizeof(Pilha)); 17 | p->topo = NULL; 18 | 19 | return p; 20 | } 21 | 22 | void push_pilha(Pilha* p, int chegada, int saida){ 23 | Item* n = (Item*) malloc(sizeof(Item)); 24 | n->chegada = chegada; 25 | n->saida = saida; 26 | n->prox = p->topo; 27 | p->topo = n; 28 | } 29 | 30 | Item pop_pilha(Pilha* p){ 31 | Item n; 32 | Item *t = (Item*) malloc(sizeof(Item)); 33 | 34 | t = p->topo; 35 | 36 | n.chegada=t->chegada; 37 | n.saida=t->saida; 38 | 39 | p->topo = t->prox; 40 | free(t); 41 | 42 | return n; 43 | } 44 | 45 | void print_pilha(Pilha* p){ 46 | Item* n = p->topo; 47 | while(n != NULL){ 48 | printf("chegada: %d, saida: %d\n", n->chegada, n->saida); 49 | n=n->prox; 50 | } 51 | } 52 | 53 | void libera_pilha(Pilha* p){ 54 | Item *n = (Item*) malloc(sizeof(Item)); 55 | n = p->topo; 56 | while(n!=NULL){ 57 | Item *t = n; 58 | n=n->prox; 59 | free(t); 60 | } 61 | p->topo = NULL; 62 | } 63 | 64 | int verifica(Pilha* p){ 65 | Item *n = (Item*) malloc(sizeof(Item)); 66 | n = p->topo; 67 | 68 | while(n!=NULL){ 69 | Item *prox = n->prox; 70 | if(prox==NULL){ 71 | return 1; 72 | } 73 | if(prox->saida < n->saida && prox->saida > n->chegada){ 74 | return 0; 75 | } 76 | n = prox; 77 | } 78 | return 1; 79 | } 80 | 81 | int main(){ 82 | 83 | Pilha* L = cria_pilha(); 84 | 85 | int n, k, c, s, v; 86 | 87 | scanf("%d %d\n",&n, &k); 88 | 89 | while(n!=0&&k!=0){ 90 | for(int i=0; itopo==NULL){ 93 | push_pilha(L,c,s); 94 | k--; 95 | } 96 | else{ 97 | if(L->topo->saida < c){ 98 | pop_pilha(L); 99 | k++; 100 | } 101 | push_pilha(L,c,s); 102 | k--; 103 | } 104 | } 105 | 106 | v = verifica(L); 107 | if(v) printf("Sim\n"); 108 | else printf("Nao\n"); 109 | // next case testing loop 110 | libera_pilha(L); 111 | scanf("%d %d",&n, &k); 112 | } 113 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/bingo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/beecrowd(merda)/bingo.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/botasperdidas.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int organiza(int m[],char l[],int n) 5 | { 6 | int x = 0; 7 | 8 | for(int i=1;i<=n;i++){ 9 | for(int j=2;j<=n;j++){ 10 | if(m[i] == m[j] && l[i] != l[j]){ 11 | if(l[i]!='V' && l[j]!= 'V'){ 12 | l[i] = 'V'; 13 | l[j] = 'V'; 14 | x+=1; 15 | } 16 | } 17 | } 18 | } 19 | printf("%d\n",x); 20 | } 21 | 22 | int main() { 23 | int n; 24 | 25 | int m[10000]; 26 | char l[10000]; 27 | 28 | while(scanf("%d",&n)!=EOF){ 29 | for(int i=1; i<=n; i++){ 30 | scanf("%d %c",&m[i],&l[i]); 31 | } 32 | organiza(m,l,n); 33 | } 34 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/botasperdidas.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/beecrowd(merda)/botasperdidas.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/cartaFora.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct lista{ 5 | int info; 6 | struct lista* prox; 7 | } Lista; 8 | 9 | typedef struct fila{ 10 | Lista* ini; 11 | Lista* fim; 12 | } Fila; 13 | 14 | Fila* cria_fila(){ 15 | Fila* f = (Fila *) malloc(sizeof(Fila)); 16 | f->ini = f->fim = NULL; 17 | return f; 18 | } 19 | 20 | void insere_fila(Fila *f, int v){ 21 | Lista* n = (Lista *) malloc(sizeof(Lista)); 22 | n->info = v; 23 | n->prox = NULL; 24 | 25 | if(f->fim!=NULL){ 26 | f->fim->prox = n; 27 | } 28 | else f->ini = n; 29 | f->fim = n; 30 | } 31 | 32 | int fila_vazia(Fila* f){ 33 | return f->ini==NULL; 34 | } 35 | 36 | int retira_fila(Fila* f){ 37 | Lista* t; 38 | int v; 39 | 40 | if(fila_vazia(f)) exit(-1); 41 | 42 | t = f->ini; 43 | v = t->info; 44 | f->ini = t->prox; 45 | if(f->ini==NULL) f->fim=NULL; 46 | free(t); 47 | return v; 48 | } 49 | 50 | void imprime_fila(Fila* f){ 51 | Lista* q; 52 | printf("Resantes: "); 53 | for(q = f->ini; q!=NULL; q=q->prox){ 54 | printf("%d", q->info); 55 | } 56 | printf("\n"); 57 | } 58 | 59 | void libera_fila(Fila* f){ 60 | Lista* q = f->ini; 61 | while(q!=NULL){ 62 | Lista* t = q->prox; 63 | free(q); 64 | q=t; 65 | } 66 | free(f); 67 | } 68 | 69 | int main(){ 70 | 71 | int n; 72 | 73 | scanf("%d", &n); 74 | while(n!=0){ 75 | int descarta[n-1]; 76 | Fila* cartas = cria_fila(); 77 | // preenche fila 78 | for(int i=1; i<=n; i++){ 79 | insere_fila(cartas, i); 80 | } 81 | 82 | // loop retira 83 | int i = 0; 84 | while(cartas->ini->prox != NULL){ 85 | descarta[i] = retira_fila(cartas); 86 | insere_fila(cartas, retira_fila(cartas)); 87 | i++; 88 | } 89 | 90 | printf("descarta cards: "); 91 | for(int i=0; i 2 | #include 3 | #include 4 | typedef struct carnes 5 | { 6 | int N; 7 | char Nl[100]; 8 | }carnes; 9 | 10 | int compara(struct carnes carnes[],struct carnes troca[],int pecas){ 11 | 12 | for(int j=1;j<=pecas;j++){ 13 | for(int i=1;i<=pecas;i++){ 14 | if(carnes[j].N 2 | 3 | int numPlacas(int v, int n){ 4 | int aux; 5 | char aux2; 6 | 7 | for(int i=1; i<10;i++){ 8 | //printf("%d",((v * n * i)/10)+1); 9 | if((v*n*i)%10){ 10 | aux = ((v*n*i)/10)+1; 11 | }else{ 12 | aux=(v*n*i)/10; 13 | } 14 | 15 | if(i<9){ 16 | aux2 = ' '; 17 | }else{ 18 | aux2 = '\n'; 19 | } 20 | printf("%d%c",aux,aux2); 21 | } 22 | } 23 | 24 | int main() { 25 | int n,v; 26 | scanf("%d %d",&v,&n); 27 | numPlacas(v,n); 28 | } 29 | -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/corrida.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/beecrowd(merda)/corrida.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/interruptor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool compara( int inicial, int atual , int m) 4 | { 5 | for( int i = 0; i < m; i++ ) 6 | { 7 | if( inicial[i] != atual[i] ) 8 | { 9 | return true; 10 | } 11 | } 12 | return false; 13 | } 14 | 15 | bool off(int atual, int m) 16 | { 17 | for(int i = 0; i < m; i++ ) 18 | { 19 | if(atual[i] != -1) 20 | { 21 | return false; 22 | } 23 | } 24 | return true; 25 | } 26 | 27 | int main() 28 | { 29 | int n,m,l,x,k,y,cont; 30 | scanf("%d, %d", &n, &m); 31 | 32 | int lampadas[m],inicial[m]; 33 | int interruptores[n]; 34 | 35 | for(int i = 0; i 2 | #include 3 | using namespace std; 4 | 5 | bool comparador(int *inicial, int *atual, int m){ 6 | for(int i = 0; i < m; i++){ 7 | if(inicial[i] != atual[i]){ 8 | return true; 9 | } 10 | } 11 | return false; 12 | } 13 | 14 | bool desligado(int *atual, int m){ 15 | for(int i = 0; i < m; i++){ 16 | if(atual[i] != -1){ 17 | return false; 18 | } 19 | } 20 | return true; 21 | 22 | } 23 | 24 | int main(){ 25 | 26 | int n, m, l, x, k, y, cont; 27 | //scanf("%d,%d",&n,&m); 28 | cin>>n>>m; 29 | 30 | 31 | int lampadas[m], inicial[m]; 32 | 33 | vector interruptores[n]; 34 | 35 | 36 | for(int i = 0; i < m; i++){ 37 | lampadas[i] = -1; 38 | } 39 | //scanf("%d",&l); 40 | cin>>l; 41 | for(int i = 0; i < l; i++){ 42 | //scanf("%d",&x); 43 | cin>>x; 44 | lampadas[x-1] *= -1; 45 | } 46 | 47 | for(int i = 0; i < n; i++){ 48 | //scanf("%d",&k); 49 | cin>>k; 50 | for(int j = 0; j < k; j++){ 51 | //scanf("%d",&y); 52 | cin>>y; 53 | interruptores[i].push_back(y-1); 54 | } 55 | } 56 | 57 | for(int i = 0; i < m; i++){ 58 | inicial[i] = lampadas[i]; 59 | } 60 | 61 | cont = 0; 62 | if(desligado(lampadas, m)){ 63 | //printf("0\n"); 64 | cout<<0< 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | int qtde; 24 | //#define TAM 1 25 | typedef struct 26 | { 27 | char nome[50]; 28 | float p1; 29 | float p2; 30 | float media; 31 | 32 | // media = (p1 + p2)/2; 33 | 34 | }Tcad; 35 | 36 | 37 | int main() 38 | { 39 | system("cls"); 40 | Tcad cad_aluno[qtde]; 41 | int opcao,i; 42 | setlocale(LC_ALL,""); 43 | printf("Insira a quantidade de alunos: "); 44 | scanf("%d",&qtde); 45 | do 46 | { 47 | printf("\nCadastro dos Alunos: \n"); 48 | printf("Digite o numero de uma das opções: \n"); 49 | printf("1- Cadastrar aluno \n"); 50 | printf("2- Listar alunos \n"); 51 | printf("3- Listar media de alunos \n"); 52 | printf("0- Sair \n"); 53 | scanf("%d", &opcao); 54 | 55 | 56 | if (opcao == 1) 57 | { 58 | 59 | for (i = 0; i 2 | #include 3 | 4 | typedef struct item{ 5 | char info; 6 | struct item *prox; 7 | } Item; 8 | 9 | typedef struct lista{ 10 | Item *ini; 11 | Item *last; 12 | Item *fim; 13 | } Lista; 14 | 15 | Lista* criaLista(){ 16 | Lista* p = (Lista*) malloc(sizeof(Lista)); 17 | p->ini = NULL; 18 | p->last = NULL; 19 | p->fim = NULL; 20 | return p; 21 | } 22 | 23 | Lista* insere(Lista *L, char info){ 24 | Item *n = (Item*) malloc(sizeof(Item)); 25 | n->info = info; 26 | n->prox = NULL; 27 | 28 | if(L->ini == NULL){ 29 | L->ini = n; 30 | L->last = n; 31 | L->fim = n; 32 | 33 | return L; 34 | } 35 | 36 | L->fim->prox = n; 37 | L->fim = n; 38 | L->last = n; 39 | 40 | return L; 41 | } 42 | 43 | Lista* insereFim(Lista *L, char info){ 44 | Item *n = (Item*) malloc(sizeof(Item)); 45 | n->info = info; 46 | if(L->ini == NULL){ 47 | L->ini = n; 48 | L->last = n; 49 | L->fim = n; 50 | 51 | return L; 52 | } 53 | 54 | if(L->last->prox == NULL){ 55 | L->fim = n; 56 | } 57 | 58 | n->prox = L->last->prox; 59 | L->last->prox = n; 60 | L->last = n; 61 | 62 | return L; 63 | } 64 | 65 | Lista* insereIni(Lista *L, char info){ 66 | Item *n = (Item*) malloc(sizeof(Item)); 67 | n->info = info; 68 | if(L->ini == NULL){ 69 | L->ini = n; 70 | L->last = n; 71 | L->fim = n; 72 | 73 | return L; 74 | } 75 | 76 | n->prox = L->ini; 77 | L->ini = n; 78 | L->last = n; 79 | 80 | return L; 81 | } 82 | 83 | void print_posordem(Item* ini){ 84 | if(ini != NULL){ 85 | printf("%c", ini->info); 86 | print_posordem(ini->prox); 87 | } 88 | } 89 | 90 | void libera_lista(Lista* L){ 91 | Item *n = L->ini; 92 | while(n!=NULL){ 93 | Item *t = n; 94 | n=t->prox; 95 | free(t); 96 | } 97 | L->ini = NULL; 98 | L->last = NULL; 99 | L->fim = NULL; 100 | } 101 | 102 | int main(){ 103 | Lista* L = criaLista(); 104 | 105 | char leitura; 106 | 107 | int mudaTxt=0; 108 | 109 | while(scanf("%c",&leitura)!=EOF){ 110 | switch(leitura){ 111 | case '[': 112 | mudaTxt = 1; 113 | break; 114 | case '\n': 115 | print_posordem(L->ini); 116 | printf("\n"); 117 | mudaTxt = 0; 118 | libera_lista(L); 119 | break; 120 | 121 | case']': 122 | mudaTxt = 2; 123 | break; 124 | default: 125 | if(mudaTxt==1) insereIni(L, leitura); 126 | if(mudaTxt==2) insere(L, leitura); 127 | if(mudaTxt==0) insereFim(L, leitura); 128 | 129 | mudaTxt = 0; 130 | break; 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/testes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int organiza(int pe[],char lado[],int pares){ 5 | 6 | int quant_pares = 0; 7 | 8 | int i,j; 9 | for(i=1;i<=pares;i++){ 10 | for(j=2;j<=pares;j++){ 11 | if(pe[i] == pe[j] && lado[i] != lado[j]){ 12 | if(lado[i]!='V' && lado[j]!= 'V'){ // LADO = V QUER DIZER QUE JÁ FOI VERIFICADO 13 | lado[i] = 'V'; 14 | lado[j] = 'V'; 15 | quant_pares+=1; 16 | } 17 | } 18 | } 19 | } 20 | printf("%d\n",quant_pares); 21 | } 22 | 23 | 24 | int main() { 25 | int pares; 26 | 27 | int pe[10000]; 28 | char lado[10000]; 29 | 30 | while(scanf("%d",&pares)!=EOF){ 31 | for(int i=1; i<=pares; i++){ 32 | scanf("%d %c",&pe[i],&lado[i]); 33 | } 34 | organiza(pe,lado,pares); 35 | } 36 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/beecrowd(merda)/testes.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/beecrowd(merda)/testes.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/Prova.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char texto[50]; 8 | int i,c, conta=0; 9 | 10 | 11 | fgets(texto, 150, stdin); 12 | 13 | c = strlen(texto); 14 | 15 | printf("Numero de letras = %d", c); 16 | 17 | for(i=0; texto[i] != '\0'; i++){ 18 | 19 | if(texto[i]==' ') { 20 | 21 | conta++; 22 | } 23 | 24 | }printf(" %d",conta+1); 25 | 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/Prova.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/p2/Prova.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/funcoes.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Lista de Funções! 4 | /* 5 | float CtoF(float x,char opc) 6 | { 7 | float c,f,temp; 8 | 9 | if (opc == '1') 10 | { 11 | c = x; 12 | temp = c*9/5 + 32; 13 | printf("%f",temp); 14 | return temp; 15 | } 16 | 17 | else if(opc == '2') 18 | { 19 | f = x; 20 | temp = (f-32)*5/9; 21 | printf("%f",temp); 22 | return temp; 23 | } 24 | else if(opc != '1'&&opc != '2') 25 | { 26 | printf("\nInsira a opc entre (1) pra C to F & (2) para F to C : "); 27 | scanf("%c",&opc); 28 | } 29 | 30 | return printf("%f",temp); 31 | } 32 | int main() 33 | { 34 | float x; 35 | char opc; 36 | printf("\nInsira a opc entre (1) pra C to F & (2) para F to C : "); 37 | scanf("%c",&opc); 38 | 39 | printf("\nInsira a temp que quiser: "); 40 | scanf("%f",&x); 41 | CtoF(x,opc); 42 | } 43 | */ 44 | /* 45 | int numPrimo(int num) 46 | { 47 | int resultado=0; 48 | for (int i = 2; i <= num/2; i++) 49 | { 50 | if (num % i == 0) 51 | { 52 | resultado++; 53 | } 54 | } 55 | if (resultado == 0) 56 | printf("1 = Primo"); 57 | else 58 | printf("0 = N Primo"); 59 | } 60 | 61 | int main () 62 | { 63 | int num; 64 | printf("\nInsira um num: "); 65 | scanf("%d",&num); 66 | numPrimo(num); 67 | } 68 | */ 69 | /* 70 | int mdc(int num1, int num2) 71 | { 72 | int resto; 73 | 74 | do { 75 | resto = num1 % num2; 76 | 77 | num1 = num2; 78 | num2 = resto; 79 | 80 | } while (resto != 0); 81 | 82 | return printf("%d",num1); 83 | } 84 | int mmc(int num1, int num2){ 85 | 86 | int resto, a, b; 87 | 88 | a = num1; 89 | b = num2; 90 | 91 | do { 92 | resto = a % b; 93 | 94 | a = b; 95 | b = resto; 96 | 97 | } while (resto != 0); 98 | 99 | return printf("%d",( num1 * num2) / a); 100 | } 101 | int main() 102 | { 103 | mdc(3,6); 104 | mmc(3,6); 105 | } 106 | */ 107 | 108 | -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/funcoes.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/p2/funcoes.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/p2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/FACULDADE/Projeto em C/p2/p2.exe -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/p2q1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //1) 4 | int main (){ 5 | int m, v, c, t; 6 | 7 | scanf("%d\n", &m); 8 | scanf("%d\n", &v); 9 | scanf("%d\n", &c); 10 | scanf("%d", &t); 11 | 12 | if (m - c - v - t >=0){ 13 | printf("\n 3"); 14 | //return 0; 15 | 16 | } else if (c + v < m || c + t < m || v + t < m){ 17 | printf("\n 2"); 18 | //return 0; 19 | 20 | } else if (c < m || v < m || t < m){ 21 | printf("\n 1"); 22 | //return 0; 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /FACULDADE/Projeto em C/p2/p2q2.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #define TAMANHO 10 5 | 6 | int main() 7 | { 8 | int i,num1,frequencia[10]={0},vetor[TAMANHO]={0}; 9 | srand(time(NULL)); 10 | 11 | for(i=0;icapacidade = c; 14 | f->dados = (float*) malloc (f->capacidade * sizeof(float)); 15 | f->primeiro = 0; 16 | f->ultimo = -1; 17 | f->nItens = 0; 18 | 19 | } 20 | 21 | void inserir(struct Fila *f, int v) { 22 | 23 | if(f->ultimo == f->capacidade-1) 24 | f->ultimo = -1; 25 | 26 | f->ultimo++; 27 | f->dados[f->ultimo] = v; // incrementa ultimo e insere 28 | f->nItens++; // mais um item inserido 29 | 30 | } 31 | 32 | int remover( struct Fila *f ) { // pega o item do começo da fila 33 | 34 | int temp = f->dados[f->primeiro++]; // pega o valor e incrementa o primeiro 35 | 36 | if(f->primeiro == f->capacidade) 37 | f->primeiro = 0; 38 | 39 | f->nItens--; // um item retirado 40 | return temp; 41 | 42 | } 43 | 44 | int estaVazia( struct Fila *f ) { // retorna verdadeiro se a fila está vazia 45 | 46 | return (f->nItens==0); 47 | 48 | } 49 | 50 | int estaCheia( struct Fila *f ) { // retorna verdadeiro se a fila está cheia 51 | 52 | return (f->nItens == f->capacidade); 53 | } 54 | 55 | void mostrarFila(struct Fila *f){ 56 | 57 | int cont, i; 58 | 59 | for ( cont=0, i= f->primeiro; cont < f->nItens; cont++){ 60 | 61 | printf("%.2f\t",f->dados[i++]); 62 | 63 | if (i == f->capacidade) 64 | i=0; 65 | 66 | } 67 | printf("\n\n"); 68 | 69 | } 70 | 71 | void main () { 72 | 73 | int opcao, capa; 74 | float valor; 75 | struct Fila umaFila; 76 | 77 | // cria a fila 78 | printf("\nCapacidade da fila? "); 79 | scanf("%d",&capa); 80 | criarFila(&umaFila, capa); 81 | 82 | // apresenta menu 83 | while( 1 ){ 84 | 85 | printf("\n1 - Inserir elemento\n2 - Remover elemento\n3 - Mostrar Fila\n0 - Sair\n\nOpcao? "); 86 | scanf("%d", &opcao); 87 | 88 | switch(opcao){ 89 | 90 | case 0: exit(0); 91 | 92 | case 1: // insere elemento 93 | if (estaCheia(&umaFila)){ 94 | 95 | printf("\nFila Cheia!!!\n\n"); 96 | 97 | } 98 | else { 99 | 100 | printf("\nValor do elemento a ser inserido? "); 101 | scanf("%f", &valor); 102 | inserir(&umaFila,valor); 103 | 104 | } 105 | 106 | break; 107 | 108 | case 2: // remove elemento 109 | if (estaVazia(&umaFila)){ 110 | 111 | printf("\nFila vazia!!!\n\n"); 112 | 113 | } 114 | else { 115 | 116 | valor = remover(&umaFila); 117 | printf("\n%1f removido com sucesso\n\n", valor) ; 118 | 119 | } 120 | break; 121 | 122 | case 3: // mostrar fila 123 | if (estaVazia(&umaFila)){ 124 | 125 | printf("\nFila vazia!!!\n\n"); 126 | 127 | } 128 | else { 129 | 130 | printf("\nConteudo da fila => "); 131 | mostrarFila(&umaFila); 132 | 133 | } 134 | break; 135 | 136 | default: 137 | printf("\nOpcao Invalida\n\n"); 138 | 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /Lista Duplamente Encadeada/listaDuplaEncad.c: -------------------------------------------------------------------------------- 1 | struct listaD{ 2 | int info; 3 | int listaD *ant; 4 | int listaD *prox; 5 | }; 6 | typedef struct listaD LstD; 7 | 8 | // Função de inserir. 9 | 10 | LstD lstDInsere(LstD* l, int v){ 11 | LstD* novo = (LstD*)malloc(sizeof(LstD)); 12 | novo->info = v; 13 | novo->listaD = l; 14 | novo->ant=NULL; 15 | // Verifica se lista tá vazia. 16 | 17 | if( l != NULL ){ 18 | l->ant = novo; 19 | } 20 | return novo; 21 | } 22 | 23 | // Função de busca. 24 | 25 | LstD* lstDBusca(LstD* l, int v){ 26 | LstD* p; 27 | for(p=l;p!=NULL;p=p->prox){ 28 | if(p->info == v){ 29 | return p; 30 | } 31 | } 32 | return NULL; 33 | } 34 | -------------------------------------------------------------------------------- /Pilha/pilha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/Pilha/pilha -------------------------------------------------------------------------------- /Pilha/pilha.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Criação da Pilha. 6 | 7 | struct pilha{ 8 | int topo; // Topo da Pilha. 9 | int base; // Base da Pilha, usado pra comparações. 10 | float *pElem; // Usado para o elemtento. 11 | }; 12 | 13 | 14 | // Cria a pilha. 15 | 16 | void createPilha(struct pilha *p, int pos){ 17 | p->topo = -1; 18 | p-> base = pos; 19 | p->pElem =(float*)malloc(pos * sizeof(float)); 20 | } 21 | 22 | // Verificações. 23 | 24 | int isEmpty(struct pilha* p){ 25 | if(p->topo == -1) return 1; 26 | else return 0; 27 | } 28 | 29 | int isFull(struct pilha* p){ 30 | if(p->topo == p->base-1) return 1; 31 | else return 0; 32 | } 33 | // Cria a função que insere valores na pilha. 34 | 35 | void push(struct pilha* p, float v){ 36 | p->topo++; 37 | p->pElem[p->topo] = v; 38 | } 39 | 40 | // Cria a função que retira elemento do topo. 41 | 42 | float pop(struct pilha* p){ 43 | float aux = p->pElem[p->topo]; 44 | p->topo--; 45 | return aux; 46 | } 47 | 48 | // Cria uma função que retorna o topo. 49 | 50 | float returnTopo(struct pilha* p){ 51 | return p->pElem[p->topo]; 52 | system("pause"); 53 | } 54 | 55 | // Função principal. 56 | 57 | int main(){ 58 | system("clear"); 59 | setlocale(LC_ALL,""); 60 | struct pilha Pilha; 61 | // Declaração de Variáveis. 62 | int tam, opc; 63 | float num; 64 | 65 | printf("Capacidade da pilha: "); 66 | scanf("%d", &tam); 67 | printf("\n"); 68 | 69 | // Chamada da função. 70 | createPilha(&Pilha,tam); 71 | 72 | // Menu 73 | 74 | do{ 75 | system("clear"); 76 | printf("\n[1] Push\n[2] Pop\n[3] Mostra topo\n[0] Sair\n"); 77 | scanf("%d", &opc); 78 | switch(opc){ 79 | case 1: 80 | if(isFull(&Pilha)==1){ 81 | printf("Stack Overflow!\n"); 82 | } 83 | else{ 84 | printf("Valor a ser inserido: "); 85 | scanf("%f", &num); 86 | push(&Pilha, num); 87 | printf("Valor inserido com sucesso. \n"); 88 | system("read -p \"Pressione ENTER para sair\" saindo\n"); 89 | } 90 | break; 91 | case 2: 92 | if(isEmpty(&Pilha)==1){ 93 | printf("Stack Underflow!\n"); 94 | } 95 | else{ 96 | num = pop(&Pilha); 97 | printf("Valor: %.2f foi retirado.\n", num); 98 | } 99 | break; 100 | case 3: 101 | if(isEmpty(&Pilha)== 1){ 102 | printf("Stack Underflow!\n"); 103 | } 104 | else{ 105 | num = returnTopo(&Pilha); 106 | printf("Valor: %.2f\n", num); 107 | system("read -p \"Pressione ENTER para sair!\" saindo"); 108 | } 109 | break; 110 | case 0: 111 | return 0; 112 | free(&Pilha); 113 | break; 114 | default: 115 | printf("Invalid input!\n"); 116 | break; 117 | } 118 | }while(opc!=0); 119 | } -------------------------------------------------------------------------------- /Pilha/testeP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/Pilha/testeP -------------------------------------------------------------------------------- /Pilha/testeP.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | struct Pilha { 7 | 8 | int topo; /* posição elemento topo */ 9 | int capa; 10 | float *pElem; 11 | 12 | }; 13 | 14 | void criarpilha( struct Pilha *p, int c ){ 15 | 16 | p->topo = -1; 17 | p->capa = c; 18 | p->pElem = (float*) malloc (c * sizeof(float)); 19 | 20 | } 21 | int estavazia ( struct Pilha *p ){ 22 | 23 | if( p-> topo == -1 ) 24 | 25 | return 1; // true 26 | 27 | else 28 | 29 | return 0; // false 30 | 31 | } 32 | 33 | int estacheia ( struct Pilha *p ){ 34 | 35 | if (p->topo == p->capa - 1) 36 | 37 | return 1; 38 | 39 | else 40 | 41 | return 0; 42 | 43 | } 44 | 45 | void empilhar ( struct Pilha *p, float v){ 46 | 47 | p->topo++; 48 | p->pElem [p->topo] = v; 49 | 50 | } 51 | 52 | float desempilhar ( struct Pilha *p ){ 53 | 54 | float aux = p->pElem [p->topo]; 55 | p->topo--; 56 | return aux; 57 | 58 | } 59 | 60 | float retornatopo ( struct Pilha *p ){ 61 | 62 | return p->pElem [p->topo]; 63 | 64 | } 65 | 66 | int main(){ 67 | setlocale(LC_ALL,""); 68 | struct Pilha minhapilha; 69 | int capacidade, op; 70 | float valor; 71 | 72 | printf( "\nCapacidade da pilha? " ); 73 | scanf( "%d", &capacidade ); 74 | 75 | criarpilha (&minhapilha, capacidade); 76 | 77 | while( 1 ){ /* loop infinito */ 78 | 79 | printf("\n1- empilhar (push)\n"); 80 | printf("2- desempilhar (POP)\n"); 81 | printf("3- Mostrar o topo \n"); 82 | printf("4- sair\n"); 83 | printf("\nopcao? "); 84 | scanf("%d", &op); 85 | 86 | switch (op){ 87 | 88 | case 1: //push 89 | 90 | if( estacheia( &minhapilha ) == 1 ) 91 | 92 | printf("\nPILHA CHEIA! \n"); 93 | 94 | else { 95 | 96 | printf("\nVALOR? "); 97 | scanf("%f", &valor); 98 | empilhar (&minhapilha, valor); 99 | 100 | } 101 | break; 102 | 103 | case 2: //pop 104 | if ( estavazia(&minhapilha) == 1 ) 105 | 106 | printf( "\nPILHA VAZIA! \n" ); 107 | 108 | else{ 109 | 110 | valor = desempilhar (&minhapilha); 111 | printf ( "\n%.1f DESEMPILHADO!\n", valor ); 112 | 113 | } 114 | break; 115 | 116 | case 3: // mostrar o topo 117 | if ( estavazia (&minhapilha) == 1 ) 118 | 119 | printf( "\nPILHA VAZIA!\n" ); 120 | 121 | else { 122 | 123 | valor = retornatopo (&minhapilha); 124 | printf ( "\nTOPO: %.1f\n", valor ); 125 | 126 | } 127 | break; 128 | 129 | case 4: 130 | exit(0); 131 | 132 | default: printf( "\nOPCAO INVALIDA! \n" ); 133 | } 134 | } 135 | 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Meus_codigos 2 | Espaço reservado para meus códigos 3 | -------------------------------------------------------------------------------- /Trabalho 2/trab.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hgleo/Codes/eb7de072443590a9e3c59fc1b197746633b27474/Trabalho 2/trab.c --------------------------------------------------------------------------------