how to write c++ programing for this question and just can only use iostream

0 votes
asked Feb 16 by Alan Poh

Declare a, b, m, X, with suitable data types.

Ask the user politely to input a positive real number X;

If X is one, then output one;


    If X is greater than 1, then let a = 1, b = X;

    If X is less than 1, then let a = X, b = 1;

    // from the observation from Fact 1,

    // the solution must lie between a and b.

    As long as b – a is more than 0.000001 times a, do

        Let m = the midpoint of a and b;

        If the square of m is equal to X,

            Escape from the loop;            (*)

        If the square of m is more than X,

            Let b = m;

        If the square of m is less than X,

            Let a = m;

    Output the midpoint of a and b, claim it as image;

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.