Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main (){
  4.  
  5. int ent = 0;
  6. char ind[1];
  7. int ele = 0, indice = 0, pos = 0, neg = 0, total = 0;
  8. float media = 0;
  9.  
  10. printf("Entre com uma quantia de números: digite 0 para terminar\n");
  11. do{
  12. scanf("%d", &ent);
  13. if(ent == 0)
  14. break;
  15. total++;
  16. media += ent;
  17.  
  18. if(ent > 0)
  19. pos++;
  20. if(ent < 0)
  21. neg++;
  22. }while(1);
  23.  
  24. do{
  25. printf("Escolha uma das opcoes do menu abaixo:\n\n");
  26. printf("\n1- Para imprimir a média aritmética dos valores lidos;");
  27. printf("\n2- Para imprimir quantidade de valores positivos; ");
  28. printf("\n3- Para imprimir quantidade de valores negativos; ");
  29. printf("\n4- Para imprimir o percentual de valores negativos e positivos.");
  30. printf("\ns - Sair\nOpção:\n");
  31. scanf("%s",ind);
  32.  
  33. switch(ind[0]){
  34.  
  35. case '1':
  36. printf("Média: %.2f\n", media/total);
  37. break;
  38. case '2':
  39. printf("Números positivos: %d\n", pos);
  40. break;
  41. case '3':
  42. printf("Números negativos: %d\n", neg);
  43. break;
  44. case '4':
  45. printf("Percentual positivo: %.2f\n Percentual negativo: %.2f\n", (float)100*pos/total, (float)100*neg/total);
  46. break;
  47. case 's': break;
  48.  
  49. default:
  50. printf("Opção inválida");
  51. break;
  52. }
  53.  
  54.  
  55. }while(ind[0] != 's');
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement