From: Charles Krug Newsgroups: comp.os.msdos.djgpp Subject: Re: math.h sin() function returns wrong value Date: Wed, 23 Jul 1997 08:50:54 -0400 Lines: 56 Message-ID: <33D5FE2E.2A08@pentek.com> References: <01bc8d93$99a3f7a0$2a39868b AT dgmdavies> NNTP-Posting-Host: mail.pentek.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Gareth Davies wrote: > > I'm pretty new to C, (snip) > /* Test program for sin() function and angle conversion, by Gareth Davies > 1997 > It probably isn't great code, but I was trying to figure out the problem > */ > #include > #include > #include > > void main() > { > char textangle; /* the text version of angle */ > int angle; /* the angle to be passed to sin() */ > float trigx, trigy, trigangle; /* the results of the trig and pythagoras > calculations */ > > printf("sin(45) = %f\n", sin(45)); > > printf("angle = "); > gets(textangle); /* get an angle out of 256, and store it in Your difficulty lies in a misunderstanding of trig functions under C, or BASIC or FORTRAN for tha t matter. Trig functions only understand radian measure (180degrees = PI). So instead of: printf("%f\n", sin(45)); What you really need is: const PI=3.141592 main() { float angle_deg, angle_rad; (etc) angle degrees = 45; angle radians = PI * (45/180); printf ("The sine of angle %f in degrees, %f in radians is %f\n", angle_deg, angle_rad, sin(angle_rad)); (etc) } Don't worry, you'll get it--everyone else here was new to C once too Charles