wrong code

Thread Starter

TAKYMOUNIR

Joined Jun 23, 2008
352
this code should compute sin(x+y) but give wrong answer
can you help me to fix this code
thanks
 

Attachments

Last edited:

panic mode

Joined Oct 10, 2011
2,715
#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);
}
 

panic mode

Joined Oct 10, 2011
2,715
Why define pi to twice as many sig figs as a double can represent?

Or more specifically, why not use the constant M_PI which is already in math.h?

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...? :D
 
Last edited:

WBahn

Joined Mar 31, 2012
29,978
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...? :D
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.
 
Top