Thread: problem function Sin()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    41

    problem function Sin()

    i have wrote function Sin(), didn'd use math in libary, but when it run the result error, can you help me? fix it thanks very much.
    sin(x)=Tn((-1)^k )*(x^2k+1)/(2k+1)!

    Code:
    #include <iostream>
    using namespace std;
    
    double gt(double d){
    	if(d==1||d==0)return 1;
    	return d*gt(d-1);
    }
    //
    double power(double a, int b)
    {
          double c=1;
          for (int h=0; h<b; h++) c*=a;
          return c;
    }
    //
    double Mysin(int x){
    	double Sum=0;
    	for(int i=1;i<=10;i++){
    		double tmp=gt(2*i+1);
    		Sum+=(power(-1,i)*(power(x,2*i+1)))/tmp;
    	}
    	return Sum;
    }
    void main(){
    	//MySin M;
    	int x;
    	cin>>x;
    	cout<<Mysin(x);
    }
    Last edited by llynx; 10-27-2009 at 09:01 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  4. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM