Making Calculation of IMC I'm not only getting the result 80

1
#include <stdio.h>
#include <math.h>

int main() 
{      
    float peso,altura,imc;
    imc=0;
    printf("digite seu peso ?");
    scanf("%f",&peso);
    printf("digite sua altura? ");
    scanf("%f",&altura);
    imc= (peso/pow(altura,2 )); //usando a função pow
    printf(" IMC igual a  %10.2f ",imc);

    return 0;
}

and without using the pow function

#include <stdio.h>
#include <math.h>

int main() 
{      float peso,altura,imc;
   imc=0;
    printf("digite seu peso ?");
    scanf("%f",&peso);
    printf("digite sua altura? ");
    scanf("%f",&altura);   // usando a função pow
    imc= (peso/altura*altura) ; // sem a função pow
    printf(" IMC igual a  %10.2f ",imc);

    return 0;
}
    
asked by anonymous 16.09.2018 / 04:06

1 answer

6

On the first test, it was not possible to reproduce your problem:

  

link


The second is basic math error.

First you divide weight by height, you deposit multiply by height:

     peso/altura*altura
// 1 ----^
// 2 -----------^

The result, guess what? It will be the height 1 ...


See the difference with the parentheses in the appropriate place:

imc = peso/(altura*altura);
  

link


1. except for rounding differences that are not relevant to this exercise. .

    
16.09.2018 / 04:22