Search code examples
chypotenuse

Calculating for the opposite side, given the hypotenuse and angle


May I ask what I'm doing wrong here? I'm trying to calculate for the opposite side, given the angle and hypotenuse. I feel like I'm using sine the wrong way. Need some clarification on why my code isn't working.

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

int main () {
    
    double fAngle, fHyp;
    
    printf("Angle: ");
    scanf("%lf", &fAngle);

    printf("Hypotenuse: ");
    scanf("%lf", &fHyp);
    
    
    printf("The opposite side is %lf", sin(fAngle) * fHyp);
    
    return 0;

}

Solution

  • You most likely are entering input in degree angles, while your code expects radian angles.

    You can easily convert to radians like this :

    double fAngle;
    
    printf("Angle: ");
    scanf("%lf", &fAngle);
    fAngle = fAngle * 2.0 * M_PI / 360.0
    

    π radians are equal to 180°