#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Question Question need to solve about C++


    Hello People this the first thread for me in this fourms I have a really hard Question about Algorthim I have to solve for the assignment so I wish to find the solve in this fourm the question is.

    write an algorithm for a program that calculates the value of Z as follow:

    Z = 1/1 - 1/4 - 1/16 - 1/64 - 1/256 - 1/1024

    Note: you are required to use the loop structure.

    So please anyone who now the answer or how to solve it to tell.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,367
    Rep Power
    1870
    What do you notice about the progression 1, 4, 16, 64, 256, 1024?

    Do you know what the next terms will be?

    Can you write a for loop to print this progression?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    I noticed that every number is divided by 4 but I dont know how how to write a loop to print print this progression could you give me a loop please :confused:
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,367
    Rep Power
    1870
    So for example,

    denominator = 1;

    Then in a loop
    denominator = denominator * 4;

    That's all I can say without giving you the chance to post some code of your own.

    The whole problem is only like 5 lines of code, and saying anymore would just give the whole game away.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,714
    Rep Power
    480
    The series has a finite sum, which has an analytic answer. You should compare your sum with this.

    http://www.intmath.com/series-binomial-theorem/3-infinite-geometric-series.php

    Also, you'll get a more accurate answer from the sum if you sort the terms and add them from smallest magnitude toward largest magnitude.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo