943,882 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4299
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 25th, 2008
0

Re: help needed to compute maclaurin series using c

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.
Reputation Points: 64
Solved Threads: 1
Light Poster
stewie griffin is offline Offline
35 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Do i need a better compiler?
Next Thread in C Forum Timeline: Quadratic Formula





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC