1) Are you entering angles in degrees or radians? 2) Why are you computing x/pi and y/pi? 3) Why not just add x and y?
The code does exactly what it should. Just for your info, you need to enter the angles in radians, or calculate it like here http://www.cplusplus.com/reference/clibrary/cmath/sin/.
#include <stdio.h> #include <stdlib.h> #include <math.h> const double pi=3.1415926535897932384626433832795; double a,b,s; double SIN_of_sum(double x,double y); int main(int argc, char** argv) { do { printf("enter first angle in degrees: "); scanf("%lg",&a); printf("enter second angle in degrees: "); scanf("%lg",&b); s=SIN_of_sum(a,b); printf(" SIN(%lg deg)=%g\n\n",a+b,s); } while ((a!=0) && (b!=0)); return 0; } double SIN_of_sum(double x,double y) { return sin((x+y)*pi/180); }
because i was too lazy and just pasted the value from calculator. also since I am working with variety of languages, I know that constant was defined somewhere in the math library but I didn't use it in a while (at least not in C) so I didn't bother to look it up. he just asked for something that works or compiles and that is what i did. happy...?
Not all compilers do have constants like pi defined in the math.h. This is not a part of the ANSI C standard.
Lazyness is a reasonable excuse in situations like this -- and your rationalle is just fine. i don't use the one in math.h because I don't believe it is required to be there by the standard. Also, even if I was going to, I can never remember the name.