trigonometric identities

I need the user to enter two angles in degrees in the following way: x + y or x-y.

and verify through ANSI C program the following trigonometric identities for the addition or subtraction of two angles:
The program must calculate separately the result of the left side and the right side of the equal and verify that they are equal. Show the angles to 8 decimals and the results to 4 decimals, validate the entry of the angles and finish if there is an error.

Tan (90), tan (270), etc., that is, tan (90 + 180n) for all integers n, is not defined, show the word "error" in the result, see the graph for the tangent.

The division between zero is also not defined, so you must also put "error" in the identity of the tangent when you have zero as a divisor.

Tip: see the reference for the following functions of the mathematical library: sin (), cos (), tan (), fmod () and fabs (); the trigonometric functions work with radians (180 degrees = π radians).

I made this code, but it have a lot of warnings...


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

#define PI 3.1416

int main(void)
{
float sum, res, x, y, s, c, t, ident1, ident2, ident3, divisor, dividendo;
char sig;
setlocale(LC_ALL,"");

printf("x [+-] y? ");

scanf("%f %1[+-] %f", &x, &sig, &y);

if(sig=='+')
{
sum=x+y;
{
s=(sin(sum*PI/180));
ident1=((sin (x*PI/180) * cos (y*PI/180))+(sin (y*PI/180) * cos (x*PI/180)));

c=(cos(sum*PI/180));
ident2=((cos (x*PI/180) * cos (y*PI/180))-(sin (y*PI/180) * sin (x*PI/180)));

printf("Sen (%.8f) = %.4f = %.4f \n", sum,s,ident1);
printf("Cos (%.8f) = %.4f = %.4f \n", sum,c,ident2);
}
{
t=(tan(sum*PI/180));
divisor=(tan(x*PI/180)+tan(y*PI/180));
dividendo=(1-(tan(x*PI/180)*tan(y*PI/180)));
ident3=(divisor/dividendo);

if (divisor==0)
{
printf("Tan (%.8f) = 0 = error \n", sum);
}

if(c==0)
{
printf("Tan (%.8f) = error = error \n", sum);
}
if(sum/90==1)
{
printf("Tan (%.8f) = error = error \n", sum);
}

return 0;
}
if(sig=='-')
{
res=x-y;

s=(sin(res*PI/180));
ident1=((sin (x*PI/180) * cos (y*PI/180))-(sin (y*PI/180) * cos (x*PI/180)));

c=(cos(res*PI/180));
ident2=((cos (x*PI/180) * cos (y*PI/180))+(sin (y*PI/180) * sin (x*PI/180)));

printf("Sen (%.8f) = %.4f = %.4f \n", res, s, ident1);
printf("Cos (%.8f) = %.4f = %.4f \n", res, c, ident2);
}
{
t=(tan(res*PI/180));
ident3=((tan(x*PI/180)-tan(y*PI/180))/(1+(tan(x*PI/180)*tan(y*PI/180))));

divisor=(tan(x*PI/180)-tan(y*PI/180));
dividendo=(1+(tan(x*PI/180)*tan(y*PI/180)));
ident3=(divisor/dividendo);

if (divisor==0)
{
printf("Tan (%.8f) = 0 = error \n", res);
}

if(c==0)
{
printf("Tan (%.8f) = error = error \n", res);
}
if(sum/90==1)
{
printf("Tan (%.8f) = error = error \n", res);
}
if (x=90)
{
printf("Tan (%.8f) = %.4f = error \n", res, t);
}

return 0;
}
}
}

By the way, I can only use if, and the functions of math.h
Last edited on
what warnings?
What do you want to know?

I personally would make a RTD and DTR multiplier constant to convert, and would use doubles instead of floats. You can also just take sin/cos/tan of x and y once each up front instead of so many times each.

if (x=90) this is an error. it assigns x to 90 then evaluates that as true. == is comparison.

you have a return 0 in the middle of main that makes all the code below it never execute.

Topic archived. No new replies allowed.