Commit ede72929 authored by João Denis Rodrigues's avatar João Denis Rodrigues

Adicionado Codigo de Alocacao Dinamica

parent 15054810
/* calcula a media de n notas especificadas pelo usuario */
#include <stdlib.h>
#include <stdio.h>
int main() {
double *notas, media=0;
int i, n;
printf ("Digite o numero de notas: ");
scanf ("%d", &n); /* obtem o numero de notas */
if (n < 1) { /* verifica se o numero e valido */
printf ("Numero invalido! Deve ser maior que zero.\n");
/* aloca memoria */
notas = (double*) malloc (n * sizeof(double));
for (i = 0; i < n; i++) { /* obtem as notas */
printf ("Digite a %da. nota: ", i+1);
scanf ("%lf", (notas+i));
/* calcula a media das notas */
for (i = 0; i < n; i++)
media += *(notas+i);
media /= n;
printf ("A media das notas e: %f\n", media);
free (notas); /* desaloca a memoria alocada previamente */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment