help needed to compute maclaurin series using c

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 20
Reputation: stewie griffin is an unknown quantity at this point 
Solved Threads: 0
stewie griffin stewie griffin is offline Offline
Newbie Poster

Re: help needed to compute maclaurin series using c

 
0
  #11
Jul 25th, 2008
Hi, this is the algorithm to calculate pi,
Pi = 4-4/3+4/5-4/7+4/9...= 4*((-1)^n+1)/2n-1
It's very similar to your need

  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int main()
  5. {
  6. float delta; //precision
  7. float pi=0,temp;
  8. int n=1;
  9. scanf("%f",&delta);
  10. do
  11. {
  12. temp = (pow(-1.0,n+1)/(2*n-1)*4);
  13. pi+=temp;
  14. n+=1;
  15. if (temp<0)
  16. temp*=-1;
  17. }while (temp>delta);
  18. printf("%f",pi);
  19. return 0;
  20. }
I hope I helped you
BTW… the delta must be les then zero
Last edited by stewie griffin; Jul 25th, 2008 at 9:33 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 2272 | Replies: 10
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC