sine C program with Power Series

This is a discussion on sine C program with Power Series within the C Programming forums, part of the General Programming Boards category; I don't what's wrong with this but the result is always 0.0 #include "poly.h" #include <math.h> /* * polyEval: Evaluates ...

  1. #1
    Unregistered
    Guest

    Post sine C program with Power Series

    I don't what's wrong with this but the result is always 0.0

    #include "poly.h"
    #include <math.h>
    /*
    * polyEval: Evaluates p(x) = a[0] + a[1] * x + ... + a[n] * x^n.
    * Pre: n >= 0 and array a[] has at least n+1 elements.
    */
    double polyEval(double *a, int n, double x)
    {
    int i; /* counter for the array */
    double sum=0.0;

    for (i=0; i<=n; i++){
    sum+= a[i]*pow(x,i);}
    return sum;
    }

    /*
    * sinePoly: Evaluates sin(x) using the first numTerms (nonzero) terms of
    * its infinite series.
    * Pre: 1 <= numTerms <= MAXTERMS.
    */
    double sinePoly(double x, int numTerms)
    {
    double a[MAXTERMS];

    while (numTerms >= 0){
    a[numTerms]=*blah calculations*;
    numTerms--;
    }
    return polyEval(a, numTerms, x);
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    1
    Maybe it's like that 'cause...
    in Your last starement 'return polyEval(a, numTerms, x)' in function 'double sinePoly(double x, int numTerms)' you call 'polyEval(...)' with parameter 'numTerms' which gets counted down to 0 in 'while (numTerms >= 0){...}' loop. So the loop 'for (i=0; i<=n; i++){...}' in 'double polyEval(double *a, int n, double x)' gets only executed once.

    <!Just a guess!>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 09:57 AM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  4. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 09:49 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21