Buscar

Programa em C que lê 4 notas e calcula sua média semestral e apresenta ao usuário

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

/* 
 * File: main.cpp
 * Author: joao
 *
 * Created on 30 de Março de 2016, 01:36
 */
#include <cstdlib>
#include <cstdio>
using namespace std;
float media(float n1, float n2) {
 return (n1 + n2) / 2;
}
char lerNota(float nota[]) {
 int i = 0;
 while (i < 4) {
 scanf("%f", &nota[i++]);
 if (nota[i - 1] < 0 || nota[i - 1] > 10) {
 printf("\n A nota deve ser >0 e menor que 10 \n");
 i--;
 }
 }
}
/*
 * 
 */
int main(int argc, char** argv) {
 float notas[4];
 int i = 0;
 lerNota(notas);
 while (i < 4) {
 printf("\nNota [%d] - [%.2f]\n", i, notas[i]);
 if (i % 2 == 1)
 printf("\n Media [%.2f]", media(notas[i - 1], notas[i]));
 i++;
 }
 return 0;
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Outros materiais