Code in c to calculate hypotenuse with cosine and adjacent

Asked

Viewed 100 times

0

This is the code I made to try to solve the following questionquestão 20, it’s not working, someone can help me?

#include <stdio.h>
#include <math.h>
int main() 
{
    cos(a)
    float d, hip;

    printf("qual o angulo?\n");
    scanf("%f", & a)

    printf("qual a distancia da escada até a parede?\n");
    scanf("%f", & d);

    hip = d/cos(a)

    printf("resultado:\n%f", cos(a))

    return 0;
}
  • what the error, post the code and a photo without the invalid result you received makes it difficult to help you friend!

  • 1

    What is the meaning of this line: cos(a)? Maybe you want to say: float a;

  • "not working " - what exactly is the problem ? Don’t compile ? If not compile which error ? Compiles because it is not working ?

3 answers

2

This C code can help you calculate!

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

float c1, c2, hpt, seno, cosseno, tangente;

main()
{
    c1 = 1.0; // Cateto 1
    c2 = 1.0; // Cateto 2

    hpt = pow((c1*c1)+(c2*c2),0.5); //Pitágoras

    printf("Hipotenusa é: %.2f\n\n\n", hpt);

    seno = c1/hpt;
    printf("Seno = %.2f \n",c1/hpt,seno);

    cosseno = c2/hpt;
    printf("Cosseno = %.2f \n\n",c2/hpt,cosseno);

    tangente = c1/c2;
    printf("Tangente %.2f = %.2f\n\n",c1/c2,tangente);

    system("PAUSE");
}

1

Well, that 'cos(a)' in the beginning does not make much sense because the variable 'a' was not declared and this account goes nowhere.

You also need to declare the variable 'a', and some dots and comma were missing. I made some modifications and commented below. By the way, it would be interesting to take the accent of the "until", because it will be strange on the way out.

#include <stdio.h>
#include <math.h>
int main()
{
//cos(a)  -> Esse trecho não faz sentido aqui.
float a, d, hip; //declarei a variável 'a' aqui.

printf("qual o angulo?\n");
scanf("%f", & a); //acrescentei ';'aqui

printf("qual a distancia da escada até a parede?\n"); 
scanf("%f", & d);

hip = d/cos(a); //acrescentei ';'aqui

printf("resultado:\n%f", cos(a)); //acrescentei ';'aqui

return 0;
}

0

Eai brother, quiet?

Seeing your code I see that there are some mistakes:

  • you forgot to declare the variable "a".
  • In some places lacked ";".
  • scanfs have spaces between "&" and variable.
  • His reasoning is right, but perhaps the result of the cosine presented by c does not agree with the expected in the problem, because the returned value of the cosine is in radians and in case the ideal would be to work with degrees, tries to put: cos(a * 3.141592/180)

I guess that’s it...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.