├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── LICENSE ├── README.md ├── ex01-introducaoC ├── ex01 ├── ex01-condicionais ├── ex01-condicionais.c ├── ex01-condicionalImpostoRenda ├── ex01-condicionalImpostoRenda.c ├── ex01-lacoDoWhile.c ├── ex01-lacoFor ├── ex01-lacoFor.c ├── ex01-lacoWhile ├── ex01-lacoWhile.c ├── ex01-primos ├── ex01-primos.c ├── ex01-variaveis ├── ex01-variaveis.c └── ex01.c ├── ex02-funcoes ├── ex02-primos ├── ex02-primos.c ├── ex02-primosOtimizado └── ex02-primosOtimizado.c ├── ex03-vetores ├── ex03-vetores-01 ├── ex03-vetores-01.c ├── ex03-vetores-02 ├── ex03-vetores-02.c ├── ex03-vetores-03 └── ex03-vetores-03.c ├── ex04-vetores-busca ├── ex04-vetores-busca-01 ├── ex04-vetores-busca-01-dados.txt └── ex04-vetores-busca-01.c ├── ex05-matrizes ├── ex05-matrizes-01 └── ex05-matrizes-01.c ├── ex06-beeCrowdVetores ├── ex06-preencherVetorIV └── ex06-preencherVetorIV.c ├── ex07-matrizes ├── ex07-matrizes-chuva └── ex07-matrizes-chuva.c ├── ex08-revisao ├── ex08-revisaoVetor └── ex08-revisaoVetor.c ├── ex08-revisaoMatriz.c ├── ex09-matrizes ├── ex09-matrizes └── ex09-matrizes.c ├── ex10-ponteiros ├── ex10-ponteiros-01 ├── ex10-ponteiros-01.c ├── ex10-ponteiros-02-vetor ├── ex10-ponteiros-02-vetor.c ├── ex10-ponteiros-03-arit └── ex10-ponteiros-03-arit.c ├── ex11-strings ├── ex11-strings-01 ├── ex11-strings-01.c ├── ex11-strings-02 ├── ex11-strings-02.c ├── ex11-strings-03 └── ex11-strings-03.c ├── ex12-structs ├── digitacao.txt ├── ex12-strucs-02-vetor ├── ex12-strucs-02-vetor.c ├── ex12-structs-01 └── ex12-structs-01.c └── ex13-arquivos ├── ex13-arquivos-bin-r ├── ex13-arquivos-bin-r-vetor ├── ex13-arquivos-bin-r-vetor.c ├── ex13-arquivos-bin-r-while ├── ex13-arquivos-bin-r-while.c ├── ex13-arquivos-bin-r.c ├── ex13-arquivos-bin-w ├── ex13-arquivos-bin-w-vetor ├── ex13-arquivos-bin-w-vetor.c ├── ex13-arquivos-bin-w.c ├── numeros.bin └── numerosVetor.bin /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use o IntelliSense para saber mais sobre os atributos possíveis. 3 | // Focalizar para exibir as descrições dos atributos existentes. 4 | // Para obter mais informações, acesse: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "gcc - Criar e depurar o arquivo ativo", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${fileDirname}/${fileBasenameNoExtension}", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${fileDirname}", 15 | "environment": [], 16 | "externalConsole": false, 17 | "MIMode": "gdb", 18 | "setupCommands": [ 19 | { 20 | "description": "Habilitar a reformatação automática para gdb", 21 | "text": "-enable-pretty-printing", 22 | "ignoreFailures": true 23 | } 24 | ], 25 | "preLaunchTask": "C/C++: gcc arquivo de build ativo", 26 | "miDebuggerPath": "/usr/bin/gdb" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "stdio.h": "c", 4 | "stdlib.h": "c" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc arquivo de build ativo", 6 | "command": "/usr/bin/gcc", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}/${fileBasenameNoExtension}", 13 | "-lm" 14 | ], 15 | "options": { 16 | "cwd": "${fileDirname}" 17 | }, 18 | "problemMatcher": ["$gcc"], 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true 22 | }, 23 | "detail": "Tarefa gerada pelo Depurador." 24 | } 25 | ], 26 | "version": "2.0.0" 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Marcio Bueno 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programação Estruturada (2025.1) 2 | 3 | ## Universidade Católica de Pernambuco 4 | -------------------------------------------------------------------------------- /ex01-introducaoC/ex01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01 -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-condicionais: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01-condicionais -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-condicionais.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num; 5 | printf("Digite um numero inteiro: "); 6 | scanf("%d", &num); 7 | 8 | if (num > 0) { 9 | printf("Voce digitou um numero positivo!\n"); 10 | } else if (num == 0) { 11 | printf("Voce digitou um numero neutro\n"); 12 | } else { 13 | printf("Voce digitou um numero negativo\n"); 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-condicionalImpostoRenda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01-condicionalImpostoRenda -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-condicionalImpostoRenda.c: -------------------------------------------------------------------------------- 1 | /* 2 | Faça um programa em C que solicite que o usuário digite 3 | o seu salário e você deve imprimir o percentual de 4 | desconto do Imposto de Renda. 5 | */ 6 | 7 | #include 8 | 9 | int main() { 10 | double salario; 11 | printf("CALCULO ALIQUOTA DO IMPOSTO DE RENDA\n\n"); 12 | printf("Digite o seu salario: "); 13 | scanf("%lf", &salario); 14 | if (salario <= 2259.20) { 15 | printf("A aliquota do seu imposto de renda e 0%%\n"); 16 | } else if (salario <= 2826.65) { 17 | printf("A aliquota do seu imposto de renda e 7,5%%\n"); 18 | } else if (salario <= 3751.05) { 19 | printf("A aliquota do seu imposto de renda e 15%%\n"); 20 | } else if (salario <= 4664.68) { 21 | printf("A aliquota do seu imposto de renda e 22,5%%\n"); 22 | } else { 23 | printf("A aliquota do seu imposto de renda e 27,5%%\n"); 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-lacoDoWhile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num1, num2; 5 | printf("Digite um numero inteiro: "); 6 | scanf("%d", &num1); 7 | 8 | do { 9 | printf("Digite um numero inteiro maior que %d\n", num1); 10 | scanf("%d", &num2); 11 | if (num2 <= num1) { 12 | printf("Valor digitado e invalido!\n"); 13 | } 14 | } while (num2 <= num1); 15 | 16 | printf("Existem %d valores no intervalo de %d a %d\n", 17 | num2 - num1 + 1, num1, num2); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-lacoFor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01-lacoFor -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-lacoFor.c: -------------------------------------------------------------------------------- 1 | #include 2 | //#define MAX_NUM 10 3 | const int MAX_NUM = 10; 4 | 5 | int main() { 6 | int num; 7 | printf("Numeros ate 10\n"); 8 | for (num = 1; num <= MAX_NUM; ++num) { 9 | printf("%d\n", num); 10 | } 11 | printf("\nImpares COM IF\n"); 12 | for (num = 1; num <= MAX_NUM; ++num) { 13 | if (num % 2 != 0) { 14 | printf("%d\n", num); 15 | } 16 | } 17 | printf("\nImpares SEM IF\n"); 18 | for (num = 1; num <= MAX_NUM; num += 2) { 19 | printf("%d\n", num); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-lacoWhile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01-lacoWhile -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-lacoWhile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX_REPET 5 4 | 5 | int main() { 6 | int num1, num2, qtdRepet = 1; 7 | printf("Digite um numero inteiro: "); 8 | scanf("%d", &num1); 9 | 10 | printf("Digite um numero inteiro maior que %d: ", num1); 11 | scanf("%d", &num2); 12 | 13 | while (num2 <= num1) { 14 | printf("Valor digitado e invalido!\n"); 15 | printf("Digite um numero inteiro maior que %d\n", num1); 16 | scanf("%d", &num2); 17 | } 18 | 19 | // while (num2 <= num1 && qtdRepet <= MAX_REPET) { 20 | // qtdRepet = qtdRepet + 1; 21 | // printf("Valor digitado e invalido!\n"); 22 | // printf("Digite um numero inteiro maior que %d\n", num1); 23 | // scanf("%d", &num2); 24 | // } 25 | 26 | if (qtdRepet <= MAX_REPET) { 27 | printf("Existem %d valores no intervalo de %d a %d\n", 28 | num2 - num1 + 1, num1, num2); 29 | return 0; 30 | } else { 31 | printf("Estorou a quantidade de repeticoes!\n"); 32 | return 1; 33 | } 34 | } -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-primos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01-primos -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-primos.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num; 5 | printf("Digite um numero inteiro: "); 6 | scanf("%d", &num); 7 | 8 | // ------------------ Testando se 'num' é primo ----------------- 9 | int divisor, qtdDivisores = 0; 10 | for (divisor = 1; divisor <= num; divisor += 1) { 11 | if (num % divisor == 0) { 12 | qtdDivisores += 1; 13 | } 14 | } 15 | 16 | if (qtdDivisores == 2) { 17 | printf("%d eh um numero primo!\n", num); 18 | } else { 19 | printf("%d nao eh um numero primo!\n", num); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-variaveis: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex01-introducaoC/ex01-variaveis -------------------------------------------------------------------------------- /ex01-introducaoC/ex01-variaveis.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n1; 5 | double n2; 6 | char letra1 = 'a', letra2 = 'b'; 7 | 8 | printf("Digite um valor inteiro: "); 9 | scanf("%d", &n1); 10 | 11 | printf("Digite um valor real: "); 12 | scanf("%lf", &n2); 13 | 14 | printf("Digite uma letra: "); 15 | scanf("%c", &letra1); // esse scanf irá ler o ENTER da digitação anterior 16 | scanf("%c", &letra1); 17 | 18 | printf("n1 = %d e n2 = %.2f\n", n1, n2); 19 | printf("letra1 = '%c' e letra2 = '%c'\n", letra1, letra2); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /ex01-introducaoC/ex01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Ola Turma!\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /ex02-funcoes/ex02-primos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex02-funcoes/ex02-primos -------------------------------------------------------------------------------- /ex02-funcoes/ex02-primos.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int MAX_NUM = 10000000; 4 | 5 | int ehPrimo(int num) { 6 | int qtdDivisores = 0; 7 | for (int divisor = 1; divisor <= num; divisor += 1) { 8 | if (num % divisor == 0) { 9 | qtdDivisores += 1; 10 | } 11 | } 12 | return qtdDivisores == 2; 13 | } 14 | 15 | int main() { 16 | int qtdPrimos = 0; 17 | printf("Listagem dos numeros primos entre 1 e %d\n", MAX_NUM); 18 | for (int num = 9500000; num <= MAX_NUM; num += 1) { 19 | if (ehPrimo(num)) { 20 | qtdPrimos += 1; 21 | printf("%d ", num); 22 | } 23 | } 24 | printf("\n\nExistem %d primos entre 1 e %d\n\n", qtdPrimos, MAX_NUM); 25 | return 0; 26 | } 27 | 28 | // Programa que fica solicitando números inteiros para 29 | // o usuário digitar e imprime se cada um dele é ou não 30 | // primo. Quando o usuário digitar um número <= 0, 31 | // encerra o programa 32 | // int main() { 33 | // int numero; 34 | // printf("Digite um numero inteiro positivo: "); 35 | // scanf("%d", &numero); 36 | // do { 37 | // if (ehPrimo(numero)) { 38 | // printf("%d eh primo!\n", numero); 39 | // } else { 40 | // printf("%d nao eh primo!\n", numero); 41 | // } 42 | // printf("Digite um numero inteiro (<= 0 para encerrar): "); 43 | // scanf("%d", &numero); 44 | // } while (numero > 0); 45 | // printf("Programa finalizado!\n"); 46 | // return 0; 47 | // } 48 | -------------------------------------------------------------------------------- /ex02-funcoes/ex02-primosOtimizado: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex02-funcoes/ex02-primosOtimizado -------------------------------------------------------------------------------- /ex02-funcoes/ex02-primosOtimizado.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int MAX_NUM = 10000000; 5 | 6 | int ehPrimo(int num) { 7 | if (num == 1) { 8 | return 0; 9 | } 10 | for (int divisor = 2; divisor < num / 2; divisor += 1) { 11 | if (num % divisor == 0) { 12 | return 0; 13 | } 14 | } 15 | return 1; 16 | } 17 | 18 | int ehPrimoOtimizada(int num) { 19 | int k = 1, a = 0, b = 0; 20 | long sr; 21 | switch(num) 22 | { 23 | case 1: return 0; 24 | case 2: return 1; 25 | case 3: return 1; 26 | case 4: return 0; 27 | case 5: return 1; 28 | case 6: return 0; 29 | case 7: return 1; 30 | } 31 | if (num % 2 == 0) return 0; 32 | if (num % 3 == 0) return 0; 33 | sr = (int) sqrt(num); 34 | while (b < sr) { 35 | a = (6 * k) - 1; 36 | b = (6 * k) + 1; 37 | if (num % a == 0) 38 | return 0; 39 | if (num % b == 0) 40 | return 0; 41 | k += 1; 42 | } 43 | return 1; 44 | } 45 | 46 | int main() { 47 | int qtdPrimos = 0; 48 | printf("Listagem dos numeros primos entre 1 e %d\n", MAX_NUM); 49 | for (int num = 1; num <= MAX_NUM; num += 1) { 50 | if (ehPrimoOtimizada(num)) { 51 | qtdPrimos += 1; 52 | printf("%d ", num); 53 | } 54 | } 55 | printf("\n\nExistem %d primos entre 1 e %d\n\n", qtdPrimos, MAX_NUM); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /ex03-vetores/ex03-vetores-01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex03-vetores/ex03-vetores-01 -------------------------------------------------------------------------------- /ex03-vetores/ex03-vetores-01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int QTD_ALUNOS = 3; 4 | 5 | int main() { 6 | double notas[QTD_ALUNOS]; 7 | printf("Digitacao de todas as notas da turma\n"); 8 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 9 | printf("Digite a nota %d: ", i + 1); 10 | scanf("%lf", ¬as[i]); 11 | } 12 | 13 | printf("\nImpressao de todas as notas da turma\n"); 14 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 15 | printf("Nota %d: %.2f\n", i + 1, notas[i]); 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /ex03-vetores/ex03-vetores-02: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex03-vetores/ex03-vetores-02 -------------------------------------------------------------------------------- /ex03-vetores/ex03-vetores-02.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int QTD_ALUNOS = 5; 4 | 5 | int main() { 6 | double notas[QTD_ALUNOS]; 7 | double somatorio = 0.0, media; 8 | 9 | printf("Digitacao de todas as notas da turma\n"); 10 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 11 | printf("Digite a nota %d: ", i + 1); 12 | scanf("%lf", ¬as[i]); 13 | somatorio += notas[i]; 14 | } 15 | 16 | media = somatorio / QTD_ALUNOS; 17 | printf("\nMedia da turma: %.2f\n", media); 18 | 19 | printf("\nImpressao de todas as notas da turma\n"); 20 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 21 | printf("Nota %d: %.2f\n", i + 1, notas[i]); 22 | } 23 | 24 | printf("\nImpressao de todas as notas acima da media da turma\n"); 25 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 26 | if (notas[i] > media) { 27 | printf("Nota %d: %.2f\n", i + 1, notas[i]); 28 | } 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /ex03-vetores/ex03-vetores-03: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex03-vetores/ex03-vetores-03 -------------------------------------------------------------------------------- /ex03-vetores/ex03-vetores-03.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int QTD_ALUNOS = 5; 4 | 5 | void preencherNotasTurma(double notas[QTD_ALUNOS]) { 6 | printf("Digitacao de todas as notas da turma\n"); 7 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 8 | printf("Digite a nota %d: ", i + 1); 9 | scanf("%lf", ¬as[i]); 10 | } 11 | } 12 | 13 | double calcularMediaTurma(double notas[QTD_ALUNOS]) { 14 | double somatorio = 0; 15 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 16 | somatorio += notas[i]; 17 | } 18 | return somatorio / QTD_ALUNOS; 19 | } 20 | 21 | void imprimirNotasTurma(double notas[QTD_ALUNOS]) { 22 | printf("\nImpressao de todas as notas da turma\n"); 23 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 24 | printf("Nota %d: %.2f\n", i + 1, notas[i]); 25 | } 26 | } 27 | 28 | void imprimirNotasAcimaMedia( 29 | double notas[QTD_ALUNOS], double media 30 | ) { 31 | printf("\nImpressao de todas as notas acima da media da turma\n"); 32 | for (int i = 0; i < QTD_ALUNOS; i += 1) { 33 | if (notas[i] > media) { 34 | printf("Nota %d: %.2f\n", i + 1, notas[i]); 35 | } 36 | } 37 | } 38 | 39 | int main() { 40 | double notas[QTD_ALUNOS]; 41 | double media; 42 | preencherNotasTurma(notas); 43 | media = calcularMediaTurma(notas); 44 | printf("\nMedia da turma: %.2f\n", media); 45 | imprimirNotasTurma(notas); 46 | imprimirNotasAcimaMedia(notas, media); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /ex04-vetores-busca/ex04-vetores-busca-01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex04-vetores-busca/ex04-vetores-busca-01 -------------------------------------------------------------------------------- /ex04-vetores-busca/ex04-vetores-busca-01-dados.txt: -------------------------------------------------------------------------------- 1 | 678 2 | 154 3 | 694 4 | 1000 5 | 500 6 | 0 7 | -------------------------------------------------------------------------------- /ex04-vetores-busca/ex04-vetores-busca-01.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const int QTD = 1000; 6 | 7 | // inserir o valor x de forma ordenada 8 | // pos tem o índice da próxima posição livre do vetor 9 | void inserirOrdenado(int v[QTD], int x, int pos) { 10 | while (pos > 0 && x < v[pos - 1]) { 11 | v[pos] = v[pos - 1]; 12 | pos -= 1; 13 | } 14 | v[pos] = x; 15 | } 16 | 17 | void preencherVetorAleatorio(int v[QTD]) { 18 | for (int i = 0; i < QTD; i += 1) { 19 | // v[i] = rand() % 1000 + 1; 20 | inserirOrdenado(v, rand() % 1000 + 1, i); 21 | } 22 | } 23 | 24 | void imprimirVetor(int v[QTD]) { 25 | for (int i = 0; i < QTD; i += 1) { 26 | printf("%d ", v[i]); 27 | } 28 | printf("\n"); 29 | } 30 | 31 | int buscar(int v[QTD], int x) { 32 | for (int i = 0; i < QTD; i += 1) { 33 | if (v[i] == x) { 34 | return i; 35 | } 36 | } 37 | return -1; 38 | } 39 | 40 | // APENAS utilizar se o vetor estiver ORDENADO 41 | int buscaMelhorada(int v[QTD], int x) { 42 | int i = 0; 43 | 44 | while (i < QTD && v[i] < x) { 45 | i += 1; 46 | } 47 | 48 | if (i < QTD && v[i] == x) { 49 | return i; 50 | } 51 | 52 | return -1; 53 | } 54 | 55 | // APENAS utilizar se o vetor estiver ORDENADO 56 | int buscaBinaria(int v[QTD], int x) { 57 | int inicio = 0, fim = QTD - 1, meio; 58 | while (inicio <= fim) { 59 | meio = (inicio + fim) / 2; 60 | if (v[meio] > x) { 61 | fim = meio - 1; 62 | } else if (v[meio] < x) { 63 | inicio = meio + 1; 64 | } else { 65 | return meio; 66 | } 67 | } 68 | return -1; 69 | } 70 | 71 | int main() { 72 | int numeros[QTD]; 73 | int num, pos; 74 | // srand(time(NULL)); 75 | srand(7); 76 | preencherVetorAleatorio(numeros); 77 | imprimirVetor(numeros); 78 | printf("Digite um valor entre 1 e 1000: "); 79 | scanf("%d", &num); 80 | while (num >= 1 && num <= 1000) { 81 | pos = buscaBinaria(numeros, num); 82 | if (pos != -1) { 83 | printf("O numero %d esta dentro do vetor na %da posicao!\n", num, pos + 1); 84 | } else { 85 | printf("O numero %d nao esta dentro do vetor!\n", num); 86 | } 87 | printf("Digite um valor entre 1 e 1000: "); 88 | scanf("%d", &num); 89 | } 90 | return 0; 91 | } -------------------------------------------------------------------------------- /ex05-matrizes/ex05-matrizes-01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex05-matrizes/ex05-matrizes-01 -------------------------------------------------------------------------------- /ex05-matrizes/ex05-matrizes-01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int QTD_LINHAS = 100; 4 | const int QTD_COLUNAS = 200; 5 | 6 | void preencherMatrizDigitacao(int m[][QTD_COLUNAS], int linhas, int colunas); 7 | void imprimirMatriz(int m[][QTD_COLUNAS], int linhas, int colunas); 8 | int digitarIntervalo(int min, int max); 9 | 10 | int main() 11 | { 12 | int matriz[QTD_LINHAS][QTD_COLUNAS]; 13 | int qtdLinhas, qtdColunas; 14 | printf("Digite o numero de linhas\n"); 15 | qtdLinhas = digitarIntervalo(1, QTD_LINHAS); 16 | printf("\nDigite o numero de colunas\n"); 17 | qtdColunas = digitarIntervalo(1, QTD_COLUNAS); 18 | printf("\nPreencha a matriz\n"); 19 | preencherMatrizDigitacao(matriz, qtdLinhas, qtdColunas); 20 | printf("\n\nImpressao\n"); 21 | imprimirMatriz(matriz, qtdLinhas, qtdColunas); 22 | } 23 | 24 | void preencherMatrizDigitacao(int m[][QTD_COLUNAS], int linhas, int colunas) { 25 | for (int i = 0; i < linhas; i += 1) { 26 | for (int j = 0; j < colunas; j += 1) { 27 | printf("Digite o valor de m[%d][%d]: ", i + 1, j + 1); 28 | scanf("%d", &m[i][j]); 29 | } 30 | } 31 | } 32 | 33 | void imprimirMatriz(int m[][QTD_COLUNAS], int linhas, int colunas) { 34 | for (int i = 0; i < linhas; i += 1) { 35 | for (int j = 0; j < colunas; j += 1) { 36 | printf("%d\t", m[i][j]); 37 | } 38 | printf("\n"); 39 | } 40 | } 41 | 42 | int digitarIntervalo(int min, int max) { 43 | int num; 44 | do { 45 | printf("Digite um valor entre %d e %d: ", min, max); 46 | scanf("%d", &num); 47 | } while (num < min || num > max); 48 | return num; 49 | } 50 | -------------------------------------------------------------------------------- /ex06-beeCrowdVetores/ex06-preencherVetorIV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex06-beeCrowdVetores/ex06-preencherVetorIV -------------------------------------------------------------------------------- /ex06-beeCrowdVetores/ex06-preencherVetorIV.c: -------------------------------------------------------------------------------- 1 | /* 2 | Neste problema você deverá ler 15 valores colocá-los em 2 vetores 3 | conforme estes valores forem pares ou ímpares. Só que o tamanho de 4 | cada um dos dois vetores é de 5 posições. Então, cada vez que um dos 5 | dois vetores encher, você deverá imprimir todo o vetor e utilizá-lo 6 | novamente para os próximos números que forem lidos. Terminada a leitura, 7 | deve-se imprimir o conteúdo que restou em cada um dos dois vetores, 8 | imprimindo primeiro os valores do vetor impar. Cada vetor pode ser 9 | preenchido tantas vezes quantas for necessário. 10 | 11 | Entrada 12 | A entrada contém 15 números inteiros. 13 | 14 | Saída 15 | Imprima a saída conforme o exemplo abaixo. 16 | */ 17 | 18 | #include 19 | 20 | const int QTD_NUMEROS = 15; 21 | const int TAM_VETOR = 5; 22 | 23 | void imprimir(int v[], int n, char *nomeVetor); 24 | 25 | int main() { 26 | int par[TAM_VETOR], impar[TAM_VETOR]; 27 | int num, qtdPares = 0, qtdImpares = 0; 28 | for (int i = 0; i < QTD_NUMEROS; i += 1) { 29 | scanf("%d", &num); 30 | if (num % 2 == 0) { 31 | par[qtdPares] = num; 32 | qtdPares += 1; 33 | if (qtdPares == TAM_VETOR) { 34 | imprimir(par, qtdPares, "par"); 35 | qtdPares = 0; 36 | } 37 | } else { 38 | impar[qtdImpares] = num; 39 | qtdImpares += 1; 40 | if (qtdImpares == TAM_VETOR) { 41 | imprimir(impar, qtdImpares, "impar"); 42 | qtdImpares = 0; 43 | } 44 | } 45 | } 46 | imprimir(impar, qtdImpares, "impar"); 47 | imprimir(par, qtdPares, "par"); 48 | } 49 | 50 | void imprimir(int v[], int n, char *nomeVetor) { 51 | for (int i = 0; i < n; i += 1) { 52 | printf("%s[%d] = %d\n", nomeVetor, i, v[i]); 53 | } 54 | } -------------------------------------------------------------------------------- /ex07-matrizes/ex07-matrizes-chuva: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex07-matrizes/ex07-matrizes-chuva -------------------------------------------------------------------------------- /ex07-matrizes/ex07-matrizes-chuva.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // para utilizar DBL_MAX 4 | 5 | const int QTD_ANOS = 5; 6 | const int QTD_MESES = 12; 7 | 8 | void preencherMatriz(double chuvas[QTD_ANOS][QTD_MESES]); 9 | void imprimirMatriz(double chuvas[QTD_ANOS][QTD_MESES]); 10 | void imprimirMesMaisSeco(double chuvas[QTD_ANOS][QTD_MESES]); 11 | void imprimirMediaPorMes(double chuvas[QTD_ANOS][QTD_MESES]); 12 | 13 | int main() { 14 | double chuvas[QTD_ANOS][QTD_MESES]; 15 | srand(7); 16 | preencherMatriz(chuvas); 17 | imprimirMatriz(chuvas); 18 | imprimirMesMaisSeco(chuvas); 19 | imprimirMediaPorMes(chuvas); 20 | } 21 | 22 | void preencherMatriz(double chuvas[QTD_ANOS][QTD_MESES]) { 23 | for (int i = 0; i < QTD_ANOS; i += 1) { 24 | for (int j = 0; j < QTD_MESES; j += 1) { 25 | chuvas[i][j] = (rand() % 1000) / 10.0; 26 | } 27 | } 28 | } 29 | 30 | void imprimirMatriz(double chuvas[QTD_ANOS][QTD_MESES]) { 31 | printf(" "); 32 | for (int i = 0; i < QTD_MESES; i += 1) { 33 | printf(" %2d ", i + 1); 34 | } 35 | printf("\n"); 36 | for (int i = 0; i < QTD_ANOS; i += 1) { 37 | printf("%d: ", 2020 + i); 38 | for (int j = 0; j < QTD_MESES; j += 1) { 39 | printf("%4.1f ", chuvas[i][j]); 40 | } 41 | printf("\n"); 42 | } 43 | } 44 | 45 | void imprimirMesMaisSeco(double chuvas[QTD_ANOS][QTD_MESES]) { 46 | int mes = 0, ano = 0; 47 | for (int i = 0; i < QTD_ANOS; i += 1) { 48 | for (int j = 0; j < QTD_MESES; j += 1) { 49 | if (chuvas[i][j] < chuvas[ano][mes]) { 50 | ano = i; 51 | mes = j; 52 | } 53 | } 54 | } 55 | printf("O mes/ano mais seco foi %d/%d\n", mes + 1, 2020 + ano); 56 | } 57 | 58 | void imprimirMediaPorMes(double chuvas[QTD_ANOS][QTD_MESES]) { 59 | double soma, media, mediaMesMaisSeco = DBL_MAX; 60 | int indiceMesMaisSeco = 0; 61 | for (int j = 0; j < QTD_MESES; j += 1) { 62 | soma = 0.0; 63 | for (int i = 0; i < QTD_ANOS; i += 1) { 64 | soma += chuvas[i][j]; 65 | } 66 | media = soma / QTD_ANOS; 67 | printf("A media de chuvas no mes %2d = %4.1f\n", j + 1, media); 68 | if (media < mediaMesMaisSeco) { 69 | mediaMesMaisSeco = media; 70 | indiceMesMaisSeco = j; 71 | } 72 | } 73 | printf("Em media, o mes mais seco eh %d com %.1f\n", indiceMesMaisSeco + 1, mediaMesMaisSeco); 74 | } -------------------------------------------------------------------------------- /ex08-revisao/ex08-revisaoVetor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex08-revisao/ex08-revisaoVetor -------------------------------------------------------------------------------- /ex08-revisao/ex08-revisaoVetor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int TAM = 10; 4 | 5 | int inserirVetor(int v[], int n); 6 | int imprimirVetor(int v[], int n); 7 | int inserirOrdenado(int v[], int n, int x); 8 | int criarVetorOrdenado(int vetOrig[], int vetOrd[], int tamVetOrig); 9 | int buscaBinaria(int v[], int n, int x); 10 | 11 | int main() { 12 | int vetOrig[TAM], vetOrd[100]; 13 | int tamVetOrig = 0, tamVetOrd = 0; 14 | int opcao, num, pos; 15 | do { 16 | printf("\nMENU\n\n"); 17 | printf("1 - Inserir 1 valor no vetor\n"); 18 | printf("2 - Criar vetor ordenado\n"); 19 | printf("3 - Busca Binária\n"); 20 | printf("Digite sua opcao (0 p/ finalizar): "); 21 | scanf("%d", &opcao); 22 | switch (opcao) { 23 | case 1: 24 | tamVetOrig = inserirVetor(vetOrig, tamVetOrig); 25 | printf("vetOrig = "); 26 | imprimirVetor(vetOrig, tamVetOrig); 27 | break; 28 | case 2: 29 | tamVetOrd = criarVetorOrdenado(vetOrig, vetOrd, tamVetOrig); 30 | break; 31 | case 3: 32 | tamVetOrd = criarVetorOrdenado(vetOrig, vetOrd, tamVetOrig); 33 | printf("Digite um numero para realizar a busca: "); 34 | scanf("%d", &num); 35 | pos = buscaBinaria(vetOrd, tamVetOrd, num); 36 | if (pos != -1) { 37 | printf("Achou o valor %d na posicao %d\n", num, pos + 1); 38 | } else { 39 | printf("Nao achou o valor %d\n", num); 40 | } 41 | break; 42 | default: 43 | if (opcao != 0) { 44 | printf("Opcao invalida!\n"); 45 | } 46 | break; 47 | } 48 | } while (opcao != 0); 49 | return 0; 50 | } 51 | 52 | int imprimirVetor(int v[], int n) { 53 | for (int i = 0; i < n; i += 1) { 54 | printf("%d ", v[i]); 55 | } 56 | printf("\n"); 57 | } 58 | 59 | int inserirVetor(int v[], int n) { 60 | if (n < TAM) { 61 | printf("Digite um valor inteiro: "); 62 | scanf("%d", &v[n]); 63 | return n + 1; 64 | } else { 65 | printf("Vetor cheio!\n"); 66 | return n; 67 | } 68 | } 69 | 70 | int inserirOrdenado(int v[], int n, int x) { 71 | int pos = n; 72 | if (pos < TAM) { 73 | while (pos > 0 && v[pos - 1] > x) { 74 | v[pos] = v[pos - 1]; 75 | pos -= 1; 76 | } 77 | v[pos] = x; 78 | return n + 1; 79 | } else { 80 | printf("Vetor cheio!\n"); 81 | return n; 82 | } 83 | } 84 | 85 | int criarVetorOrdenado(int vetOrig[], int vetOrd[], int tamVetOrig) { 86 | int tamVetOrd = 0; 87 | for (int i = 0; i < tamVetOrig; i += 1) { 88 | tamVetOrd = inserirOrdenado(vetOrd, tamVetOrd, vetOrig[i]); 89 | } 90 | printf("vetOrig = "); 91 | imprimirVetor(vetOrig, tamVetOrig); 92 | printf("vetOrd = "); 93 | imprimirVetor(vetOrd, tamVetOrd); 94 | return tamVetOrd; 95 | } 96 | 97 | int buscaBinaria(int v[], int n, int x) { 98 | int inicio = 0, fim = n - 1, meio; 99 | while (inicio <= fim) { 100 | meio = (inicio + fim) / 2; 101 | if (v[meio] == x) { 102 | return meio; 103 | } else if (x < v[meio]) { 104 | fim = meio - 1; 105 | } else { 106 | inicio = meio + 1; 107 | } 108 | } 109 | return -1; 110 | } -------------------------------------------------------------------------------- /ex08-revisaoMatriz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int M = 30; 4 | const int N = 20; 5 | 6 | void criarVetorMaiorColuna(int m[][N], int v[], int qtdLinhas, int qtdColunas) { 7 | int maior; 8 | for (int j = 0; j < qtdColunas; j += 1) { 9 | maior = m[0][j]; 10 | for (int i = 0; i < qtdLinhas; i += 1) { 11 | if (m[i][j] > maior) { 12 | maior = m[i][j]; 13 | } 14 | } 15 | v[j] = maior; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ex09-matrizes/ex09-matrizes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex09-matrizes/ex09-matrizes -------------------------------------------------------------------------------- /ex09-matrizes/ex09-matrizes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int ORDEM = 100; 5 | void multiplicarMatrizes( 6 | int m1[][ORDEM], int qtdLinhas1, int qtdColunas1, 7 | int m2[][ORDEM], int qtdLinhas2, int qtdColunas2, 8 | int matMult[][ORDEM] 9 | ); 10 | void preencherMatriz(int m[][ORDEM], int qtdLinhas, int qtdColunas); 11 | void imprimirMatriz(int m[][ORDEM], int qtdLinhas, int qtdColunas); 12 | void zerarAbaixoDiagPrincipal(int m[][ORDEM], int ordem); 13 | 14 | int main() { 15 | int matriz1[ORDEM][ORDEM], matriz2[ORDEM][ORDEM], matriz3[ORDEM][ORDEM]; 16 | int qtdLinhas1 = 7, qtdColunas1 = 7, qtdLinhas2 = 7, qtdColunas2 = 8; 17 | srand(7); 18 | preencherMatriz(matriz1, qtdLinhas1, qtdColunas1); 19 | preencherMatriz(matriz2, qtdLinhas2, qtdColunas2); 20 | printf("MATRIZ 1\n"); 21 | imprimirMatriz(matriz1, qtdLinhas1, qtdColunas1); 22 | printf("MATRIZ 2\n"); 23 | imprimirMatriz(matriz2, qtdLinhas2, qtdColunas2); 24 | multiplicarMatrizes( 25 | matriz1, qtdLinhas1, qtdColunas1, 26 | matriz2, qtdLinhas2, qtdColunas2, 27 | matriz3 28 | ); 29 | printf("MATRIZ 3\n"); 30 | imprimirMatriz(matriz3, qtdLinhas1, qtdColunas2); 31 | printf("\n\nMatriz Original"); 32 | imprimirMatriz(matriz1, qtdLinhas1, qtdColunas1); 33 | zerarAbaixoDiagPrincipal(matriz1, qtdLinhas1); 34 | printf("\nMatriz Zerada Abaixo Diagonal Principal\n"); 35 | imprimirMatriz(matriz1, qtdLinhas1, qtdColunas1); 36 | return 0; 37 | } 38 | 39 | void preencherMatriz(int m[][ORDEM], int qtdLinhas, int qtdColunas) { 40 | for (int i = 0; i < qtdLinhas; i += 1) { 41 | for (int j = 0; j < qtdColunas; j += 1) { 42 | m[i][j] = rand() % 10 + 1; 43 | } 44 | } 45 | } 46 | 47 | void imprimirMatriz(int m[][ORDEM], int qtdLinhas, int qtdColunas) { 48 | for (int i = 0; i < qtdLinhas; i += 1) { 49 | for (int j = 0; j < qtdColunas; j += 1) { 50 | printf("%4d ", m[i][j]); 51 | } 52 | printf("\n"); 53 | } 54 | printf("\n"); 55 | } 56 | 57 | void multiplicarMatrizes( 58 | int m1[][ORDEM], int qtdLinhas1, int qtdColunas1, 59 | int m2[][ORDEM], int qtdLinhas2, int qtdColunas2, 60 | int matMult[][ORDEM] 61 | ) { 62 | if (qtdColunas1 != qtdLinhas2) { 63 | printf("Não é possível multiplicar essas duas matrizes"); 64 | } 65 | 66 | for (int i = 0; i < qtdLinhas1; i += 1) { 67 | for (int j = 0; j < qtdColunas2; j += 1) { 68 | matMult[i][j] = 0; 69 | for (int k = 0; k < qtdColunas1; k += 1) { 70 | matMult[i][j] += m1[i][k] * m2[k][j]; 71 | } 72 | } 73 | } 74 | } 75 | 76 | void zerarAbaixoDiagPrincipal(int m[][ORDEM], int ordem) { 77 | for (int i = 1; i < ordem; i += 1) { 78 | for (int j = 0; j < i; j += 1) { 79 | m[i][j] = 0; 80 | } 81 | } 82 | } 83 | 84 | void zerarAbaixoDiagPrincipal2(int m[][ORDEM], int ordem) { 85 | for (int i = 0; i < ordem; i += 1) { 86 | for (int j = 0; j < ordem; j += 1) { 87 | if (j < i) { 88 | m[i][j] = 0; 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /ex10-ponteiros/ex10-ponteiros-01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex10-ponteiros/ex10-ponteiros-01 -------------------------------------------------------------------------------- /ex10-ponteiros/ex10-ponteiros-01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void trocar(int *a, int *b) { 4 | int aux = *a; 5 | *a = *b; 6 | *b = aux; 7 | } 8 | 9 | int main() { 10 | int numero1 = 10, numero2 = 20; 11 | printf("numero1 = %d - numero2 = %d\n", numero1, numero2); 12 | trocar(&numero1, &numero2); 13 | printf("numero1 = %d - numero2 = %d\n", numero1, numero2); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /ex10-ponteiros/ex10-ponteiros-02-vetor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex10-ponteiros/ex10-ponteiros-02-vetor -------------------------------------------------------------------------------- /ex10-ponteiros/ex10-ponteiros-02-vetor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int TAM = 4; 4 | 5 | int main() { 6 | double v[] = { 1, 2, 3, 4 }; 7 | printf("v = %p\n", v); 8 | for (int i = 0; i < TAM; i += 1) { 9 | printf("v[%d] = %f - (%p)\n", i, v[i], &v[i]); 10 | } 11 | printf("*v = %f\n", *v); 12 | printf("*(v + 1) = %f - (v + 1) = %p\n", *(v + 1), v + 1); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /ex10-ponteiros/ex10-ponteiros-03-arit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex10-ponteiros/ex10-ponteiros-03-arit -------------------------------------------------------------------------------- /ex10-ponteiros/ex10-ponteiros-03-arit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int *p; 5 | int a = 10, b = 15, c = 20; 6 | printf("&a = %p - &b = %p - &c = %p\n", &a, &b, &c); 7 | printf("a = %d - b = %d - c = %d\n", a, b, c); 8 | // via aritmética de ponteiros: só vai funcionar se a, b e c forem 9 | // criadas em posições de memória adjacentes 10 | p = &a; 11 | *p += 1; 12 | p += 1; 13 | *p += 1; 14 | p += 1; 15 | *p += 1; 16 | printf("&a = %p - &b = %p - &c = %p\n", &a, &b, &c); 17 | printf("a = %d - b = %d - c = %d\n", a, b, c); 18 | // via atribuição dos endereços de memória de cada variável 19 | // assim, sempre irá funcionar 20 | p = &a; 21 | *p += 1; 22 | p = &b; 23 | *p += 1; 24 | p = &c; 25 | *p += 1; 26 | printf("&a = %p - &b = %p - &c = %p\n", &a, &b, &c); 27 | printf("a = %d - b = %d - c = %d\n", a, b, c); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /ex11-strings/ex11-strings-01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex11-strings/ex11-strings-01 -------------------------------------------------------------------------------- /ex11-strings/ex11-strings-01.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int TAM = 100; 5 | 6 | void lerStr(char *str, int count); 7 | void myStrCpy(char *dest, char *orig); 8 | void imprimirCodigoAscii(char *str); 9 | void substituir(char *str, char antigo, char novo); 10 | 11 | int main() 12 | { 13 | char nome[TAM]; 14 | printf("Digite o seu nome: "); 15 | 16 | lerStr(nome, TAM); 17 | 18 | printf("O nome digitado foi \"%s\"\n", nome); 19 | 20 | // nome = "Maria Jose Santos"; // ERRADO!!!!! Precisa usar strcpy 21 | strcpy(nome, "Maria Jose Santos"); 22 | substituir(nome, 'a', 'e'); 23 | printf("O nome foi alterado para \"%s\"\n", nome); 24 | 25 | imprimirCodigoAscii(nome); 26 | 27 | return 0; 28 | } 29 | 30 | void lerStr(char *str, int count) { 31 | fgets(str, count, stdin); 32 | int tam = strlen(str); 33 | if (tam > 0 && str[tam - 1] == '\n') { 34 | str[tam - 1] = '\0'; 35 | } 36 | } 37 | 38 | // exemplo de como você poderia implementar o strcpy 39 | void myStrCpy(char *dest, char *orig) { 40 | int i = 0; 41 | while (orig[i] != '\0') { 42 | dest[i] = orig[i]; 43 | i += 1; 44 | } 45 | dest[i] = '\0'; 46 | } 47 | 48 | void imprimirCodigoAscii(char *str) { 49 | int tam = strlen(str); 50 | printf("CHAR\tASCII\n"); 51 | for (int i = 0; i < tam; i += 1) 52 | { 53 | printf("%c\t%d\n", str[i], str[i]); 54 | } 55 | } 56 | 57 | void substituir(char *str, char antigo, char novo) { 58 | int tam = strlen(str); 59 | for (int i = 0; i < tam; i += 1) { 60 | if (str[i] == antigo) { 61 | str[i] = novo; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ex11-strings/ex11-strings-02: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex11-strings/ex11-strings-02 -------------------------------------------------------------------------------- /ex11-strings/ex11-strings-02.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int TAM_TEMP = 256; 5 | const int QTD_PESSOAS = 3; 6 | const int TAM_NOME = 20; 7 | 8 | void lerStr(char *str, int count); 9 | 10 | int main() { 11 | char strTemp[TAM_TEMP]; 12 | char nomes[QTD_PESSOAS][TAM_NOME]; 13 | int idades[QTD_PESSOAS]; 14 | 15 | for (int i = 0; i < QTD_PESSOAS; i += 1) { 16 | printf("Digite o nome[%d]: ", i); 17 | lerStr(nomes[i], TAM_NOME); 18 | printf("Digite a idade[%d]: ", i); 19 | scanf("%d", &idades[i]); 20 | lerStr(strTemp, TAM_TEMP); 21 | } 22 | 23 | printf("\nNOMES DIGITADOS\n"); 24 | for (int i = 0; i < QTD_PESSOAS; i += 1) { 25 | printf("nomes[%d] = %-20s - idades[%d] = %3d\n", i, nomes[i], i, idades[i]); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | void lerStr(char *str, int count) { 32 | fgets(str, count, stdin); 33 | int tam = strlen(str); 34 | if (tam > 0 && str[tam - 1] == '\n') { 35 | str[tam - 1] = '\0'; 36 | } 37 | } -------------------------------------------------------------------------------- /ex11-strings/ex11-strings-03: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex11-strings/ex11-strings-03 -------------------------------------------------------------------------------- /ex11-strings/ex11-strings-03.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int TAM = 100; 5 | 6 | void lerStr(char *str, int count); 7 | int palindroma(char *str); 8 | void removerEspacos(char *str); 9 | 10 | int main() { 11 | char frase[TAM]; 12 | printf("Digite uma frase: "); 13 | 14 | lerStr(frase, TAM); 15 | 16 | printf("A frase digitada foi \"%s\" ", frase); 17 | 18 | removerEspacos(frase); 19 | 20 | if (palindroma(frase)) { 21 | printf(" e ela eh palindroma\n"); 22 | } else { 23 | printf(" e ela nao eh palindroma\n"); 24 | } 25 | 26 | printf("\nA frase modificada foi \"%s\" ", frase); 27 | 28 | return 0; 29 | } 30 | 31 | void lerStr(char *str, int count) { 32 | fgets(str, count, stdin); 33 | int tam = strlen(str); 34 | if (tam > 0 && str[tam - 1] == '\n') { 35 | str[tam - 1] = '\0'; 36 | } 37 | } 38 | 39 | // exemplo de como você poderia implementar o strcpy 40 | void myStrCpy(char *dest, char *orig) { 41 | int i = 0; 42 | while (orig[i] != '\0') { 43 | dest[i] = orig[i]; 44 | i += 1; 45 | } 46 | dest[i] = '\0'; 47 | } 48 | 49 | void imprimirCodigoAscii(char *str) { 50 | int tam = strlen(str); 51 | printf("CHAR\tASCII\n"); 52 | for (int i = 0; i < tam; i += 1) 53 | { 54 | printf("%c\t%d\n", str[i], str[i]); 55 | } 56 | } 57 | 58 | void substituir(char *str, char antigo, char novo) { 59 | int tam = strlen(str); 60 | for (int i = 0; i < tam; i += 1) { 61 | if (str[i] == antigo) { 62 | str[i] = novo; 63 | } 64 | } 65 | } 66 | 67 | int palindroma(char *str) { 68 | int tam = strlen(str); 69 | int metadeTam = tam / 2; 70 | for (int i = 0; i < metadeTam; i += 1) { 71 | if (str[i] != str[tam - 1 - i]) { 72 | return 0; 73 | } 74 | } 75 | return 1; 76 | } 77 | 78 | void removerEspacos(char *str) { 79 | int tam = strlen(str); 80 | int j = 0; 81 | for (int i = 0; i < tam; ++i) { 82 | if (str[i] != ' ') { 83 | str[j] = str[i]; 84 | j += 1; 85 | } 86 | } 87 | str[j] = '\0'; 88 | } -------------------------------------------------------------------------------- /ex12-structs/digitacao.txt: -------------------------------------------------------------------------------- 1 | Ana 2 | 17 3 | 50.9 4 | 1.67 5 | Maria 6 | 20 7 | 55 8 | 1.73 9 | Jose 10 | 21 11 | 60.4 12 | 1.65 13 | Joao 14 | 15 15 | 60.9 16 | 1.85 17 | Luiza 18 | 19 19 | 66.2 20 | 1.77 21 | Fabricio 22 | 18 23 | 50.7 24 | 1.67 25 | Valdemir 26 | 20 27 | 61.5 28 | 1.67 29 | Luana 30 | 15 31 | 55.8 32 | 1.81 33 | Paulo 34 | 19 35 | 59.5 36 | 1.85 37 | Luis 38 | 21 39 | 83.5 40 | 1.82 41 | -------------------------------------------------------------------------------- /ex12-structs/ex12-strucs-02-vetor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex12-structs/ex12-strucs-02-vetor -------------------------------------------------------------------------------- /ex12-structs/ex12-strucs-02-vetor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define QTD_PESSOAS 10 5 | #define TAM_NOME 30 6 | #define TAM_TEMP 256 7 | 8 | struct Pessoa { 9 | char nome[TAM_NOME]; 10 | int idade; 11 | double peso, altura; 12 | }; 13 | 14 | void lerStr(char *str, int count); 15 | void lerPessoa(struct Pessoa *pessoa); 16 | void imprimirPessoa(struct Pessoa pessoa); 17 | double calcularIMC(struct Pessoa pessoa); 18 | 19 | // exercícios: implemente as seguintes funções e utilize-as no main 20 | double calcularMediaAltura(struct Pessoa vp[], int tam); 21 | int encontrarPessoaMaisPesada(struct Pessoa vp[], int tam); 22 | double calcularMediaIdadeIMCnormal(struct Pessoa vp[], int tam); 23 | 24 | // campo nome 25 | int buscarPeloNome(struct Pessoa v[], int tam, char *x); 26 | int buscaBinariaPorNome(struct Pessoa v[], int tam, char *x); 27 | void insercaoDiretaCampoNome(struct Pessoa v[], int n); 28 | 29 | // campo idade 30 | int buscarPelaIdade(struct Pessoa v[], int tam, int x); 31 | int buscaBinariaPorIdade(struct Pessoa v[], int tam, int x); 32 | void insercaoDiretaCampoIdade(struct Pessoa v[], int n); 33 | 34 | int main() { 35 | struct Pessoa pessoas[QTD_PESSOAS]; 36 | char nome[TAM_NOME]; 37 | int pos, idade; 38 | 39 | for (int i = 0; i < QTD_PESSOAS; i += 1) 40 | { 41 | printf("----- Digitação dos dados da Pessoa %d -----\n", i + 1); 42 | lerPessoa(&pessoas[i]); 43 | } 44 | 45 | printf("\n\n"); 46 | 47 | for (int i = 0; i < QTD_PESSOAS; i += 1) { 48 | printf("----- Impressão dados da Pessoa %d: ", i + 1); 49 | imprimirPessoa(pessoas[i]); 50 | } 51 | 52 | insercaoDiretaCampoNome(pessoas, QTD_PESSOAS); 53 | 54 | printf("\n\n----- Impressao apos ordenacao por nome\n"); 55 | for (int i = 0; i < QTD_PESSOAS; i += 1) 56 | { 57 | printf("----- Impressão dados da Pessoa %d: ", i + 1); 58 | imprimirPessoa(pessoas[i]); 59 | } 60 | 61 | printf("\nA media de altura destas pessoas eh %.2f\n", calcularMediaAltura(pessoas, QTD_PESSOAS)); 62 | 63 | int posMaisPesada = encontrarPessoaMaisPesada(pessoas, QTD_PESSOAS); 64 | printf("\nA pessoa mais pesada eh: "); 65 | imprimirPessoa(pessoas[posMaisPesada]); 66 | 67 | printf("\nA media de idade das pessoas com IMC normal eh: %.2f\n", calcularMediaIdadeIMCnormal(pessoas, QTD_PESSOAS)); 68 | 69 | printf("Digite um nome a ser encontrado: "); 70 | lerStr(nome, TAM_NOME); 71 | pos = buscaBinariaPorNome(pessoas, QTD_PESSOAS, nome); 72 | if (pos != -1) { 73 | printf("Pessoa encontrada na posicao %d: ", pos + 1); 74 | imprimirPessoa(pessoas[pos]); 75 | } else { 76 | printf("Nao tem nenhuma pessoa com esse nome!\n"); 77 | } 78 | 79 | insercaoDiretaCampoIdade(pessoas, QTD_PESSOAS); 80 | 81 | printf("\n\n----- Impressao apos ordenacao por idade\n"); 82 | for (int i = 0; i < QTD_PESSOAS; i += 1) { 83 | printf("----- Impressão dados da Pessoa %d: ", i + 1); 84 | imprimirPessoa(pessoas[i]); 85 | } 86 | 87 | printf("Digite um nome a ser encontrado: "); 88 | scanf("%d", &idade); 89 | pos = buscaBinariaPorIdade(pessoas, QTD_PESSOAS, idade); 90 | if (pos != -1) { 91 | printf("Pessoa encontrada na posicao %d: ", pos + 1); 92 | imprimirPessoa(pessoas[pos]); 93 | } else { 94 | printf("Nao tem nenhuma pessoa com essa idade!\n"); 95 | } 96 | 97 | return 0; 98 | } 99 | 100 | void lerStr(char *str, int count) { 101 | fgets(str, count, stdin); 102 | int tam = strlen(str); 103 | if (tam > 0 && str[tam - 1] == '\n') { 104 | str[tam - 1] = '\0'; 105 | } 106 | } 107 | 108 | void lerPessoa(struct Pessoa *pessoa) { 109 | char tempStr[TAM_TEMP]; 110 | printf("Digite o nome: "); 111 | lerStr(pessoa->nome, TAM_NOME); // lerStr((*pessoa).nome, TAM_NOME); 112 | printf("Digite a idade: "); 113 | scanf("%d", &pessoa->idade); // scanf("%d", &(*pessoa).idade); 114 | printf("Digite o peso: "); 115 | scanf("%lf", &pessoa->peso); // scanf("%lf", &(*pessoa).peso); 116 | printf("Digite a altura: "); 117 | scanf("%lf", &pessoa->altura); // scanf("%lf", &(*pessoa).altura); 118 | lerStr(tempStr, TAM_TEMP); // realiza a leitura do '\n' do scanf anterior 119 | } 120 | 121 | void imprimirPessoa(struct Pessoa pessoa) { 122 | double imc = calcularIMC(pessoa); 123 | printf("(%s, %d anos, %.2f kg, %.2f m, IMC %.2f)\n", 124 | pessoa.nome, 125 | pessoa.idade, 126 | pessoa.peso, 127 | pessoa.altura, 128 | imc 129 | ); 130 | } 131 | 132 | double calcularIMC(struct Pessoa pessoa) { 133 | return pessoa.peso / (pessoa.altura * pessoa.altura); 134 | } 135 | 136 | double calcularMediaAltura(struct Pessoa vp[], int tam) { 137 | double somaAltura = 0.0, mediaAltura = 0.0; 138 | for (int i = 0; i < tam; i += 1) { 139 | somaAltura += vp[i].altura; 140 | } 141 | if (tam != 0) { 142 | mediaAltura = somaAltura / tam; 143 | } 144 | return mediaAltura; 145 | } 146 | 147 | int encontrarPessoaMaisPesada(struct Pessoa vp[], int tam) { 148 | int posMaisPesada = 0; 149 | for (int i = 1; i < tam; i += 1) { 150 | if (vp[i].peso > vp[posMaisPesada].peso) { 151 | posMaisPesada = i; 152 | } 153 | } 154 | return posMaisPesada; 155 | } 156 | 157 | double calcularMediaIdadeIMCnormal(struct Pessoa vp[], int tam) { 158 | int somaIdades = 0, qtdIdades = 0; 159 | double mediaIdades = 0.0, imc; 160 | for (int i = 0; i < tam; i += 1) { 161 | imc = calcularIMC(vp[i]); 162 | if (imc >= 18.5 && imc < 25.0) { 163 | somaIdades += vp[i].idade; 164 | qtdIdades += 1; 165 | } 166 | } 167 | if (qtdIdades != 0) { 168 | mediaIdades = (double) somaIdades / (double) qtdIdades; 169 | } 170 | return mediaIdades; 171 | } 172 | 173 | // -------- INÍCIO CAMPO NOME -------- 174 | 175 | int buscarPeloNome(struct Pessoa v[], int tam, char *x) { 176 | for (int i = 0; i < tam; i += 1) { 177 | if (strcmp(v[i].nome, x) == 0) { 178 | return i; 179 | } 180 | } 181 | return -1; 182 | } 183 | 184 | // APENAS utilizar se o vetor estiver ORDENADO 185 | int buscaBinariaPorNome(struct Pessoa v[], int tam, char *x) { 186 | int inicio = 0, fim = tam - 1, meio; 187 | while (inicio <= fim) { 188 | meio = (inicio + fim) / 2; 189 | if (strcmp(v[meio].nome, x) > 0) { 190 | fim = meio - 1; 191 | } else if (strcmp(v[meio].nome, x) < 0) { 192 | inicio = meio + 1; 193 | } else { 194 | return meio; 195 | } 196 | } 197 | return -1; 198 | } 199 | 200 | void insercaoDiretaCampoNome(struct Pessoa v[], int n) { 201 | int i, j; 202 | struct Pessoa chave; 203 | for (i = 1; i <= n - 1; i++) { 204 | chave = v[i]; 205 | j = i - 1; 206 | while (j >= 0 && strcmp(v[j].nome, chave.nome) > 0) { 207 | v[j+1] = v[j]; 208 | j = j - 1; 209 | } 210 | v[j+1] = chave; 211 | } 212 | } 213 | 214 | // -------- FIM CAMPO IDADE -------- 215 | 216 | 217 | // -------- INÍCIO CAMPO IDADE -------- 218 | 219 | int buscarPelaIdade(struct Pessoa v[], int tam, int x) { 220 | for (int i = 0; i < tam; i += 1) { 221 | if (v[i].idade == x) { 222 | return i; 223 | } 224 | } 225 | return -1; 226 | } 227 | 228 | // APENAS utilizar se o vetor estiver ORDENADO 229 | int buscaBinariaPorIdade(struct Pessoa v[], int tam, int x) { 230 | int inicio = 0, fim = tam - 1, meio; 231 | while (inicio <= fim) { 232 | meio = (inicio + fim) / 2; 233 | if (v[meio].idade > x) { 234 | fim = meio - 1; 235 | } else if (v[meio].idade < x) { 236 | inicio = meio + 1; 237 | } else { 238 | return meio; 239 | } 240 | } 241 | return -1; 242 | } 243 | 244 | void insercaoDiretaCampoIdade(struct Pessoa v[], int n) { 245 | int i, j; 246 | struct Pessoa chave; 247 | for (i = 1; i <= n - 1; i++) { 248 | chave = v[i]; 249 | j = i - 1; 250 | while (j >= 0 && v[j].idade > chave.idade) { 251 | v[j+1] = v[j]; 252 | j = j - 1; 253 | } 254 | v[j+1] = chave; 255 | } 256 | } 257 | 258 | // -------- FIM CAMPO IDADE -------- 259 | -------------------------------------------------------------------------------- /ex12-structs/ex12-structs-01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex12-structs/ex12-structs-01 -------------------------------------------------------------------------------- /ex12-structs/ex12-structs-01.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define TAM_NOME 30 5 | #define TAM_TEMP 256 6 | 7 | struct Pessoa { 8 | char nome[TAM_NOME]; 9 | int idade; 10 | double peso, altura; 11 | }; 12 | 13 | void lerStr(char *str, int count); 14 | void lerPessoa(struct Pessoa *pessoa); 15 | void imprimirPessoa(struct Pessoa pessoa); 16 | double calcularIMC(struct Pessoa pessoa); 17 | 18 | int main() { 19 | struct Pessoa pessoa1, pessoa2; 20 | printf("----- Digitação dos dados da Pessoa 1 -----\n"); 21 | lerPessoa(&pessoa1); 22 | printf("----- Digitação dos dados da Pessoa 2 -----\n"); 23 | lerPessoa(&pessoa2); 24 | 25 | printf("----- Impressão dados da Pessoa 1\n"); 26 | imprimirPessoa(pessoa1); 27 | printf("----- Impressão dados da Pessoa 2\n"); 28 | imprimirPessoa(pessoa2); 29 | return 0; 30 | } 31 | 32 | void lerStr(char *str, int count) { 33 | fgets(str, count, stdin); 34 | int tam = strlen(str); 35 | if (tam > 0 && str[tam - 1] == '\n') { 36 | str[tam - 1] = '\0'; 37 | } 38 | } 39 | 40 | void lerPessoa(struct Pessoa *pessoa) { 41 | char tempStr[TAM_TEMP]; 42 | printf("Digite o nome: "); 43 | lerStr(pessoa->nome, TAM_NOME); // lerStr((*pessoa).nome, TAM_NOME); 44 | printf("Digite a idade: "); 45 | scanf("%d", &pessoa->idade); // scanf("%d", &(*pessoa).idade); 46 | printf("Digite o peso: "); 47 | scanf("%lf", &pessoa->peso); // scanf("%lf", &(*pessoa).peso); 48 | printf("Digite a altura: "); 49 | scanf("%lf", &pessoa->altura); // scanf("%lf", &(*pessoa).altura); 50 | lerStr(tempStr, TAM_TEMP); // realiza a leitura do '\n' do scanf anterior 51 | } 52 | 53 | void imprimirPessoa(struct Pessoa pessoa) { 54 | double imc = calcularIMC(pessoa); 55 | printf("(%s, %d anos, %.2f kg, %.2f m, IMC %.2f)\n", 56 | pessoa.nome, 57 | pessoa.idade, 58 | pessoa.peso, 59 | pessoa.altura, 60 | imc 61 | ); 62 | } 63 | 64 | double calcularIMC(struct Pessoa pessoa) { 65 | return pessoa.peso / (pessoa.altura * pessoa.altura); 66 | } -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex13-arquivos/ex13-arquivos-bin-r -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-r-vetor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex13-arquivos/ex13-arquivos-bin-r-vetor -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-r-vetor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define TAM 10 4 | void imprimirVetor(int v[], int tam); 5 | 6 | int main() { 7 | int numeros[TAM]; 8 | int status; 9 | FILE *arq = fopen("numerosVetor.bin", "rb"); 10 | if (arq == NULL) { 11 | printf("Nao conseguiu abrir o arquivo!\n"); 12 | return 1; 13 | } 14 | 15 | status = fread(numeros, sizeof(int), TAM, arq); 16 | if (status != TAM) { 17 | printf("erro ao ler vetor numeros\n"); 18 | } 19 | 20 | imprimirVetor(numeros, TAM); 21 | 22 | if (fclose(arq) == 0) 23 | { 24 | printf("Arquivo fechado com sucesso!"); 25 | } 26 | else 27 | { 28 | printf("Erro ao fechar o arquivo!"); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | void imprimirVetor(int v[], int tam) { 35 | for (int i = 0; i < tam; i += 1) { 36 | printf("numeros[%d]: %3d\n", i + 1, v[i]); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-r-while: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex13-arquivos/ex13-arquivos-bin-r-while -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-r-while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num; 5 | FILE *arq = fopen("numerosVetor.bin", "rb"); 6 | if (arq == NULL) { 7 | printf("Nao conseguiu abrir o arquivo!\n"); 8 | return 1; 9 | } 10 | 11 | fread(&num, sizeof(int), 1, arq); 12 | while (!feof(arq)) { 13 | printf("%3d\n", num); 14 | fread(&num, sizeof(int), 1, arq); 15 | } 16 | 17 | if (fclose(arq) == 0) 18 | { 19 | printf("Arquivo fechado com sucesso!"); 20 | } 21 | else 22 | { 23 | printf("Erro ao fechar o arquivo!"); 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-r.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num1 = 0, num2 = 0, num3 = 0, num4 = 0; 5 | int status; 6 | FILE *arq = fopen("numeros.bin", "rb"); 7 | if (arq == NULL) { 8 | printf("Nao conseguiu abrir o arquivo!\n"); 9 | return 1; 10 | } 11 | 12 | status = fread(&num1, sizeof(int), 1, arq); 13 | if (status != 1) { 14 | printf("erro ao ler num1\n"); 15 | } 16 | 17 | status = fread(&num2, sizeof(int), 1, arq); 18 | if (status != 1) { 19 | printf("erro ao ler num2\n"); 20 | } 21 | 22 | status = fread(&num3, sizeof(int), 1, arq); 23 | if (status != 1) { 24 | printf("erro ao ler num3\n"); 25 | } 26 | 27 | status = fread(&num4, sizeof(int), 1, arq); 28 | if (status != 1) { 29 | printf("erro ao ler num4\n"); 30 | } 31 | 32 | printf("valores lidos do arquivo: %d, %d, %d, %d\n\n", 33 | num1, num2, num3, num4); 34 | 35 | if (fclose(arq) == 0) 36 | { 37 | printf("Arquivo fechado com sucesso!"); 38 | } 39 | else 40 | { 41 | printf("Erro ao fechar o arquivo!"); 42 | } 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-w: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex13-arquivos/ex13-arquivos-bin-w -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-w-vetor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex13-arquivos/ex13-arquivos-bin-w-vetor -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-w-vetor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define TAM 10 4 | 5 | int main() { 6 | int numeros[TAM] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 7 | int status; 8 | FILE *arq = fopen("numerosVetor.bin", "wb"); 9 | if (arq == NULL) { 10 | printf("Nao conseguiu abrir o arquivo!\n"); 11 | return 1; 12 | } 13 | 14 | status = fwrite(numeros, sizeof(int), TAM, arq); 15 | if (status == TAM) { 16 | printf("vetor numeros gravado com sucesso!\n"); 17 | } else { 18 | printf("erro ao salvar o vetor numeros\n"); 19 | } 20 | 21 | if (fclose(arq) == 0) { 22 | printf("Arquivo fechado com sucesso!\n"); 23 | } else { 24 | printf("Erro ao fechar o arquivo!\n"); 25 | } 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /ex13-arquivos/ex13-arquivos-bin-w.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num1 = 8, num2 = 1000, num3 = -234; 5 | int status; 6 | FILE *arq = fopen("numeros.bin", "wb"); 7 | if (arq == NULL) { 8 | printf("Nao conseguiu abrir o arquivo!\n"); 9 | return 1; 10 | } 11 | 12 | status = fwrite(&num1, sizeof(int), 1, arq); 13 | if (status == 1) { 14 | printf("num1 gravado com sucesso!\n"); 15 | } else { 16 | printf("erro ao salvar num1\n"); 17 | } 18 | 19 | status = fwrite(&num2, sizeof(int), 1, arq); 20 | if (status == 1) { 21 | printf("num2 gravado com sucesso!\n"); 22 | } else { 23 | printf("erro ao salvar num2\n"); 24 | } 25 | 26 | status = fwrite(&num3, sizeof(int), 1, arq); 27 | if (status == 1) { 28 | printf("num3 gravado com sucesso!\n"); 29 | } else { 30 | printf("erro ao salvar num3\n"); 31 | } 32 | 33 | if (fclose(arq) == 0) { 34 | printf("Arquivo fechado com sucesso!"); 35 | } else { 36 | printf("Erro ao fechar o arquivo!"); 37 | } 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /ex13-arquivos/numeros.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marciobueno1/pe-2025-1/070113b538ee9d008e258dffe291fef91c9571b2/ex13-arquivos/numeros.bin -------------------------------------------------------------------------------- /ex13-arquivos/numerosVetor.bin: -------------------------------------------------------------------------------- 1 |  2 | --------------------------------------------------------------------------------