Skip to content

Instantly share code, notes, and snippets.

@ivanelson
Created December 14, 2018 22:35
Show Gist options
  • Save ivanelson/b0487a7ff5abd8f68e44acde2f5a0f22 to your computer and use it in GitHub Desktop.
Save ivanelson/b0487a7ff5abd8f68e44acde2f5a0f22 to your computer and use it in GitHub Desktop.
media com do-while in "C"
#include <stdio.h>
#include <stdlib.h>
void main() {
float nota, soma = 0, media;
int resp, contador = 0;
do {
printf("Digita a nota: ");
scanf("%f", &nota);
soma = soma + nota;
printf("\nDigite 1 para continuar ou digite outra tecla para finalizar...: ");
scanf("%d", &resp);
contador++; // o mesmo que contador = contador + 1
} while (resp == 1);
media = soma / contador;
printf("\nA media da turma eh %.2f \n", media);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment