Last active
August 20, 2021 18:33
-
-
Save divanibarbosa/a7aaca83dcb80ba04f8f34548f6b335d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Criado por: profa. Divani Barbosa Gavinier | |
// Curriculo Lattes: http://lattes.cnpq.br/8503400830635447 | |
// divanibarbosa@gmail.com | |
/* | |
Escreva um programa em linguagem C que solicita ao usuário a quantidade de alunos de uma turma e aloca um vetor de notas (números reais). Depois de ler as notas, imprime a média aritmética. | |
Obs: não deve ocorrer desperdício de memória, após ser utilizada a memória deve ser devolvida ao sistema operacional. Use as funções de alocação dinâmica de memória da linguagem. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
main() { | |
int qtde, i; | |
printf("Informe a quantidade de alunos: "); | |
scanf("%d",&qtde); | |
float *nota = (float *) malloc(qtde*sizeof(float)); | |
if (nota == NULL) { | |
printf("Memoria Indisponivel\n\n"); | |
exit(0); | |
} | |
float media=0.0; | |
printf("\nInforme as notas\n"); | |
for(i=0; i<qtde; i++) { | |
printf("Nota do aluno %d: ",i+1); | |
scanf("%f",¬a[i]); | |
media = media + nota[i]; | |
} | |
media = media/qtde; | |
printf("\nMedia = %.2f\n\n", media); | |
free(nota); | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment