Advertisement
bombardelli

EXERCICIO ALGORITMO DE 1 A 5

Apr 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. float LerPositivoInteiro(){
  5. int num;
  6. do{
  7. scanf("%d", &num);
  8. if(num < 0){
  9. printf("Numero negativo. Informe novamente!");
  10. }
  11. }while(num <0);
  12. return num;
  13.  
  14. }
  15.  
  16. float LerPositivoReal(){
  17. float num;
  18. do{
  19. scanf("%f", &num);
  20. if(num < 0){
  21. printf("Numero negativo. Informe novamente!");
  22. }
  23. }while(num <0);
  24. return num;
  25.  
  26. }
  27.  
  28.  
  29. float imc(float peso, float altura){
  30. float IMC;
  31. IMC = peso / (altura*altura);
  32. return IMC;
  33. }
  34.  
  35. void imprimeimc(int idade, float imc){
  36.  
  37. if(idade <= 30){
  38. if(imc<17){
  39. printf("Muito magra\n");
  40. }else
  41. if(imc<22){
  42. printf("Magra\n");
  43. }else
  44. if(imc<27){
  45. printf("Normal\n");
  46. }else
  47. if(imc<33){
  48. printf("Acima\n");
  49. }else{
  50. printf("Obesa\n");
  51. }
  52. }else{
  53. if(imc<18){
  54. printf("\nMuito magra");
  55. }else
  56. if(imc<24){
  57. printf("\nMagra\n");
  58. }else
  59. if(imc<27){
  60. printf("\nNormal");
  61. }else
  62. if(imc<31){
  63. printf("\nAcima");
  64. }else{
  65. printf("\nObesa\n");
  66. }
  67. }
  68. }
  69.  
  70. int main()
  71. {
  72. int idade;
  73. float peso, altura;
  74. float valorimc;
  75. int x;
  76.  
  77. printf("Insira a sua idade:");
  78. idade = LerPositivoInteiro();
  79. printf("Insira o valor do peso:");
  80. peso = LerPositivoReal();
  81. printf("Insira o valor da altura:");
  82. altura = LerPositivoReal();
  83.  
  84. valorimc = imc(peso, altura);
  85. printf("O valor do IMC: %f", valorimc);
  86. imprimeimc(idade, valorimc);
  87.  
  88.  
  89.  
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement