/** * ============================================================================ * PHM Open Source — Curso de Lógica e Programação em C * Módulo 04: Vetores Unidimensionais (Arrays) e Matrizes * Autor: Prof. Paulo Henrique Maciel · PHM Tech * ============================================================================ * * OBJETIVO DIDÁTICO: * Compreender armazenamento contíguo de dados homogêneos na memória, indexação * de base zero, busca linear, maior/menor valor e matrizes bidimensionais. * * COMO COMPILAR E EXECUTAR: * gcc 04_vetores_e_matrizes.c -o modulo04 && ./modulo04 * ============================================================================ */ #include #define TAM_VETOR 5 #define NUM_ALUNOS 3 #define NUM_BIMESTRES 4 int main(void) { printf("====================================================\n"); printf(" PHM TECH — MODULO 04: VETORES E MATRIZES \n"); printf("====================================================\n\n"); // 1. VETOR UNIDIMENSIONAL (ARRAY DE INTEIROS) int numeros[TAM_VETOR] = {42, 17, 88, 5, 63}; int maior = numeros[0]; int menor = numeros[0]; int soma = 0; printf("[1] Analise de Vetor Unidimensional (%d elementos):\n", TAM_VETOR); for (int i = 0; i < TAM_VETOR; i++) { printf(" - Elemento no indice [%d] = %d (Endereco: %p)\n", i, numeros[i], (void*)&numeros[i]); soma += numeros[i]; if (numeros[i] > maior) maior = numeros[i]; if (numeros[i] < menor) menor = numeros[i]; } float media = (float)soma / TAM_VETOR; printf("\nEstatisticas do Vetor:\n"); printf(" -> Maior Elemento : %d\n", maior); printf(" -> Menor Elemento : %d\n", menor); printf(" -> Media dos Itens: %.2f\n\n", media); // 2. MATRIZ BIDIMENSIONAL (TABELA DE NOTAS POR BIMESTRE) // Linhas = Alunos | Colunas = Notas dos 4 Bimestres float boletim[NUM_ALUNOS][NUM_BIMESTRES] = { {8.5f, 7.0f, 9.0f, 8.0f}, // Aluno 1 {6.0f, 5.5f, 7.0f, 6.5f}, // Aluno 2 {9.5f, 9.0f, 10.0f, 9.5f} // Aluno 3 }; printf("[2] Matriz de Notas (%d Alunos x %d Bimestres):\n", NUM_ALUNOS, NUM_BIMESTRES); printf("----------------------------------------------------\n"); printf(" Aluno | 1º Bim | 2º Bim | 3º Bim | 4º Bim | Media Final\n"); printf("----------------------------------------------------\n"); for (int i = 0; i < NUM_ALUNOS; i++) { float somaAluno = 0.0f; printf(" Aluno %d |", i + 1); for (int j = 0; j < NUM_BIMESTRES; j++) { printf(" %4.1f |", boletim[i][j]); somaAluno += boletim[i][j]; } float mediaAluno = somaAluno / NUM_BIMESTRES; printf(" %4.1f %s\n", mediaAluno, mediaAluno >= 7.0f ? "[APROV]" : "[RECUP]"); } printf("----------------------------------------------------\n"); return 0; }