Advertisement
LightProgrammer000

Média Final [Crescente e Decrescente]

Nov 22nd, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.73 KB | None | 0 0
  1. /// Bibliotecas
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <conio.h>
  6.  
  7. /// Protótipos
  8. float Media(float soma, int cont);
  9.  
  10. /// Programa
  11. int main ( int argc, char * argv [] )
  12. {
  13.     // Configurações de Idioma
  14.     setlocale(LC_ALL, "");
  15.  
  16.     // Variavel Estratégica [Controle de Fluxo]
  17.     char decisao = 's';
  18.  
  19.     while ( decisao != 'n' && decisao != 'N' )
  20.     {
  21.         // Variaveis
  22.         int a, i, j;
  23.         int TAM,aux;
  24.         int cont = 0;
  25.         float soma = 0;
  26.  
  27.         // Tela
  28.         system("cls & color F");
  29.         printf(" ----------------\n");
  30.         printf("       MÉDIA      \n");
  31.         printf(" -----------------\n\n");
  32.  
  33.         // Entrada de Dados
  34.         printf("- Deseja Inserir quantas Notas ?\n");
  35.         printf("- Opc: ");
  36.         scanf("%d",&TAM);
  37.         printf("\n");
  38.  
  39.         // Variável [Tamanho do Armazenamento do Vetor]
  40.         float nota[TAM];
  41.  
  42.         // Estrutura de Repetição [Entrada de Dados]
  43.         for ( i = 0; i < TAM; i ++ )
  44.         {
  45.             printf("- Digite a Nota[%d]: ",i+1);
  46.             scanf("%f",&nota[i]);
  47.  
  48.             // Somatório de Notas
  49.             soma += nota[i];
  50.             cont+=1;
  51.         }
  52.  
  53.         system("cls & color B");
  54.         printf(" ------------------------\n");
  55.         printf("       RESULTADOS      \n");
  56.         printf(" ------------------------\n\n");
  57.  
  58.         // Apresentação [Vetor]
  59.         printf("\n *** Notas ***\n");
  60.         for ( i = 0; i < TAM; i++ )
  61.         {
  62.             printf("\n- Nota[%d]: %.2f", i + 1, nota[i] );
  63.         }
  64.  
  65.         // Estrutura de Repetição [Ordem Crescente]
  66.         for ( i = 0; i < TAM; i ++ )
  67.         {
  68.             for ( j = 0; j < i + 1; j ++ )
  69.             {
  70.                 if ( nota[j] > nota[i] )
  71.                 {
  72.                     aux = nota[i];
  73.                     nota[i] = nota[j];
  74.                     nota[j] = aux;
  75.                 }
  76.             }
  77.         }
  78.  
  79.         // Apresentação
  80.         printf("\n\n *** Notas em Ordem Crescente ***\n");
  81.         for ( i = 0; i < TAM; i++ )
  82.         {
  83.             printf("\n- Nota[%d]: %.2f", i + 1, nota[i] );
  84.         }
  85.  
  86.         // Estrutura de Repetição [Ordem Decrescente]
  87.         for ( i = 0; i < TAM; i ++ )
  88.         {
  89.             for ( j = 0; j < i + 1; j ++ )
  90.             {
  91.                 if ( nota[j] < nota[i] )
  92.                 {
  93.                     aux = nota[i];
  94.                     nota[i] = nota[j];
  95.                     nota[j] = aux;
  96.                 }
  97.             }
  98.         }
  99.  
  100.         // Apresentação
  101.          printf("\n\n *** Notas em Ordem Decrescente ***\n");
  102.         for ( i = 0; i < TAM; i++ )
  103.         {
  104.             printf("\n- Nota[%d]: %.2f", i + 1, nota[i] );
  105.         }
  106.  
  107.         //////////////////////////////////////////////////////
  108.  
  109.         // Apresentação
  110.         printf("\n\n");
  111.         system("pause & cls & color F");
  112.         printf(" ------------------------\n");
  113.         printf("       SITUAÇÃO      \n");
  114.         printf(" ------------------------\n\n");
  115.  
  116.         // Estrutura de Decisão
  117.         if ( Media(soma, cont) >= 7 )
  118.         {
  119.             // Sistema: Cor Verde
  120.             system("color A");
  121.  
  122.             // Variavel
  123.             char sit[] = "Aprovado!!!";
  124.  
  125.             // Apresentação
  126.             for ( a = 0; a < sizeof(sit); a++ )
  127.             {
  128.                 printf("\n%c", sit[a]);
  129.             }
  130.  
  131.             printf("\n- Média: %.2f \n", Media(soma, cont) );
  132.         }
  133.  
  134.         else if ( Media(soma, cont ) < 7 && Media(soma, cont) >= 4 )
  135.         {
  136.             // Sistema: Cor Amarelo
  137.             system("color E");
  138.  
  139.             // Variavel
  140.             char sit[] = "Recuperação";
  141.  
  142.             // Apresentação
  143.             printf("\n- Situação: %s \n", sit );
  144.             printf("\n- Média: %.2f \n", Media(soma, cont) );
  145.         }
  146.  
  147.         else
  148.         {
  149.             // Sistema: Cor Vermelho
  150.             system("color C");
  151.  
  152.             // Variavel
  153.             char sit[] = "Reprovado";
  154.  
  155.             // Estrutura de Repetição
  156.             for( a = ( sizeof(sit) - 1 ); a >= 0; a-- )
  157.             {
  158.                 printf("\n%c", sit[a]);
  159.             }
  160.  
  161.             // Apresentação
  162.             printf("\n- Média: %.2f \n", Media(soma, cont) );
  163.         }
  164.  
  165.  
  166.         // Retorno ao Menu
  167.         printf("\n\n- Deseja voltar ao Menu Principal: \n[s] - Sim \n[n] - Não\n");
  168.         printf("\n- Opc: ");
  169.         decisao = getche();
  170.     }
  171.  
  172.     return(0);
  173. }
  174.  
  175. /////////////////////////// FUNCOES ///////////////////////////
  176.  
  177. /// Média
  178. float Media(float soma, int cont)
  179. {
  180.     // Variáveis
  181.     float media;
  182.  
  183.     // Cálculo da Média
  184.     media = ( soma / cont );
  185.  
  186.     // Retorno
  187.     return(media);
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement