Purchase Solution

Algorithms to print the daily salary of a worker

Not what you're looking for?

Ask Custom Question

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?

Purchase this Solution

Solution Summary

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

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, " - ", ...

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.