renix1

Calcular nota, 4 alunos 4 bimestres

Feb 4th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. float mediaAlunos[4]; //variavel global por padrão estática
  4. int main(void) {
  5.     float notas[4][4]; //variavel que armazena o tanto de alunos e os 4 bimestres
  6.     int aluno, bimestre = 0;
  7.     void calculo_media(float notas[][4], int posMatriz); //protótipo da função
  8.     void ordem_crescente(float mediaAlunos[], int posVetor); //protótipo da função
  9.     printf("-- SOFTWARE CALCULO DE NOTAS --\n"); //exibe mensagem
  10.     for (aluno = 0; aluno < 4; aluno++) {
  11.         for (bimestre = 0; bimestre < 4; bimestre++) {
  12.             printf("Digite a nota do aluno %d: ", aluno+1); //pede pro usuario digitar algo
  13.             scanf("%f", &notas[aluno][bimestre]); //recebe a entrada do usuario
  14.             if (notas[aluno][bimestre] > 10) { //verifica se a nota é maior que 10
  15.                 printf("Notas acima de 10 nao permitidas.\n");
  16.                 exit(0);
  17.             }
  18.         }
  19.     }
  20.     calculo_media(notas, 4); //inicia a função
  21.     ordem_crescente(mediaAlunos, 4); //inicia a função
  22.     system("pause");
  23.     return(0);
  24. }
  25. void calculo_media (float notas[][4], int posMatriz) {
  26.     int aluno, bimestre;
  27.     //Calcula a media final do aluno
  28.     for (aluno = 0; aluno < 4; aluno++) {
  29.         printf("Calculando...\n");
  30.         for (bimestre = 0; bimestre < 4; bimestre++) {
  31.             mediaAlunos[aluno] = notas[aluno][bimestre] / 4;
  32.         }
  33.     }
  34. }
  35. void ordem_crescente (float mediaAlunos[], int posVetor) {
  36.     int atual, prox, temporario;
  37.     //Organinzando em ordem crescente
  38.     for (atual = 0; atual < 4; atual++) {
  39.         printf("-- ORGANIZANDO EM ORDEM CRESCENTE --\n");
  40.         for (prox = atual + 1; prox < 4; prox++) {
  41.             if (mediaAlunos[atual] > mediaAlunos[prox]) {
  42.                     temporario = mediaAlunos[prox];
  43.                     mediaAlunos[atual] = mediaAlunos[prox];
  44.                     mediaAlunos[prox] = temporario;
  45.             }
  46.         }
  47.     }
  48.     //Exibindo para o usuário
  49.     for (atual = 0; atual < 4; atual++) {
  50.         printf("Media %d: %.3f\n", atual+1, mediaAlunos[atual]);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment