Explore BrainMass
Share

Explore BrainMass

    Algorithms to print the daily salary of a worker

    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 October 10, 2019, 1:31 am ad1c9bdddf
    https://brainmass.com/computer-science/program-execution/algorithms-print-daily-salary-worker-338264

    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.

    $2.19