my homework is to make a c program displayin de cosine series.....i made up one referrin buks but can it be made simpler or somethin using while statements..........

   int fact(int);//Global defenition
void main()
//to find the power pow(number,power);
//to find root sqrt(number)-- in math.h

float cosx(float,int);

float x;
int n;
float final;

cout<<"\n Enter the limit ";
cout<<"\n enter the value for x ";

cout<<"\n sum of cos series  for "<<n<<" terms is "<<final;

float cosx(float x,int lm)

   float term;
    float sum=1;
	for (int i=0;i<lm-1;i++)
  		//find factorial of c
  	int c=2;



int fact(int num)
{int res=1;
     for (int  j=1;j<=num;j++)
       { res=res*j;}

Votes + Comments
Because each post you make, you post your rubbish without using code tags, and you refuse the advice to use code tags each time.
9 Years
Discussion Span
Last Post by wildgoose

Is using code tags really that difficult for you?
Haven't you found the button yet, after 49 posts?

Information about code tags is found all over the website:

1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in!

How can you just neglect that? There's no explanation solid enough to not use code tags.
Please come back when you've learned how to use code tags, and when you've learned to use int main() instead of void main() . void main() is evil, but some people just don't seem to get it.

Come on, you started your thread in the wrong forum and it seems like you're still not aware of the fact that you won't get helped.
It's maybe better to not waste your time on wasting my time, I would really appreciate that.


> You cannot give more Reputation to anuizath2007 today.
I'll be back!

Haha, bookmarked in my reputation queue :P


you have a problem! You set c =2 inside the loop but add 2 to it at the bottom of the loop, which gets replaced at the top of the loop with 2 again.

I made your factorial incremental so that your function runs faster.
Also you're using floats' but you're using the double function pow(), where when using floats, you should be using powf().

You may want to re-examine your function and see if it realy does what you wanted!

float cosx(float x,int lm)
   float term;
   float sum=1;

     // Calculate our factorial on the fly
   float fkt = 1.0f * 2.0f;     // !2
   int c = 2;

   for (int i=0; i < lm-1; i++)
      term = - powf( x, c ) / fkt;
       sum = sum + term;

      fkt = fkt * (float)c++;  // Factorial xN   x (N+1)
      fkt = fkt * (float)c++;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.