Advertisement
LightProgrammer000

Cálculo Média Aritmética [Tempo Real]

Nov 22nd, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. /// Bibliotecas
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /// Programa
  6. int main ()
  7. {
  8.     // Variaveis
  9.     int cont = 1;
  10.     float nota, soma, media;
  11.  
  12.     // Apresentação
  13.     printf("===========================\n");
  14.     printf("     PROGRAMA DA MEDIA     \n");
  15.     printf("===========================\n");
  16.  
  17.     while( nota != -1 )
  18.     {
  19.         printf("\n NOTA %d <Para sair digite [-1] >: ", cont);
  20.         scanf("%f",&nota);
  21.  
  22.         // Estrutura de Decisao: Caso [-1]
  23.         if ( nota == -1 )
  24.         {
  25.             break;
  26.         }
  27.  
  28.         else
  29.         {
  30.             // Contador
  31.             cont ++;
  32.  
  33.             // Cálculo
  34.             soma = soma + nota;
  35.             continue;
  36.         }
  37.     }
  38.  
  39.     // Cálculo da Média
  40.     if ( cont != 1 )
  41.     {
  42.         media = soma / ( cont - 1 );
  43.         printf("\n MEDIA: %.2f \n", media);
  44.     }
  45.  
  46.     else
  47.     {
  48.         printf("\n CALCULO NAO REALIZADO \n");
  49.     }
  50.  
  51.     return (0);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement