Explore BrainMass

Explore BrainMass

    Algorithms to print the daily salary of a worker

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Develop two algorithms (one iterative and one recursive) to print the daily salary of a worker who, each day, is paid twice the previous day's salary (starting with one penny for the first day's work) for a 30 day period.

    What problems are you likely to encounter if you implement your solutions on an actual machine?

    © BrainMass Inc. brainmass.com November 30, 2021, 4:13 am ad1c9bdddf

    Solution Preview

    Following two algorithms have been expressed in C-style pseudocode.

    function iterativeWay ()
    // For the first day salary is 1 penny.
    salaryForDay = 1
    day = 1

    while (day <= 30)
    print day, " - ", salaryForDay;

    // Be ready for next iteration/day
    day = day + 1
    salaryForDay = 2 * salaryForDay

    function recursiveWay (day, salaryForDay)
    if (day <= 30)
    print day, " - ", ...

    Solution Summary

    Algorithms have been expressed in C-style pseudo-code.