Calculation of sine values in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhamb
    New Member
    • Feb 2008
    • 18

    #1

    Calculation of sine values in C

    I have to complete a task related to calculation of Sine values.
    I made whole of the program but the first value Im getting, i.e. a * Sin(0), is always displayed as 10 rather than 0.

    This is the loop code I tried :
    Code:
    //All the values a,f,fs.... are of float type.           
    	for(n = 0;n <= N-1; n++)
    	{
    		double *s = malloc(sizeof(double));
    		double *x = malloc(sizeof(double));
    		*x = (2 *  PI  * (f / fs)* n);         
                   *s = a * sin(*x);
    		printf("%f\n",*s);
    	}
    Anyone can help...!
    Thanks :):):)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Beats me. sin(0) is 0. 0 times anything is 0.

    Comment

    • jhamb
      New Member
      • Feb 2008
      • 18

      #3
      Originally posted by weaknessforcats
      Beats me. sin(0) is 0. 0 times anything is 0.

      Yeah..!! That is what I know. But everytime it came out to be 10 instead 0..
      So, I posted... I found a bug in the code, just above the loop.
      That was printing an extra 1 before 0....

      Now its done with full accuracy..! :))

      Comment

      Working...