Explore BrainMass
Share

Most favorite loop structure

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

What is the most favorite loop structure, and why?
How might you use it in a real business programming problem?

Give an example of how you might use a C array to solve a real life business problem.
Extra(notreally!): post a code sample too.

© BrainMass Inc. brainmass.com October 16, 2018, 10:12 pm ad1c9bdddf
https://brainmass.com/computer-science/sorting/what-is-the-most-favorite-loop-structure-and-why-212542

Solution Preview

In loop structure, FOR loop is the most favorite one.
Unlike many other kinds of loops, such as the while loop, the for loop is often distinguished by an explicit loop counter or loop variable. This allows the body of the for loop (the code that is being repeatedly executed) to know about the sequencing of each iteration. For loops are also typically used when the number of iterations is known before entering the loop.
Consider a business firm, a program is written to find out number of old timers in that firm. For that program, a first FOR loop is used to iterate each employee and a second FOR loop is used inside the first FOR loop for each department. so from this program the old timers can easily be sort out from every department, using nested FOR loops.

Following program is used to sort the products in a market. So sorting algorithm is used in this program, using arrays.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ...

Solution Summary

The solution determines the most favorite loop structure. An example using a C array is analyzed.

$2.19
Similar Posting

Discrete Math:Recursion

Discussion Questions

1. List all the steps used to search for 9 in the sequence 1,3, 4, 5, 6, 8, 9, 11 using a binary search.
2. Describe an induction process. How does induction process differ from a process of simple repetition?
3. Describe a favorite recreational activity in terms of its iterative components, such as solving a crossword or Sudoku puzzle or playing a game of chess or backgammon. Also, mention any recursive elements that occur.
4. Describe a situation in your professional or personal life when recursion, or at least the principle of recursion, played a role in accomplishing a task, such as a large chore that could be decomposed into smaller chunks that were easier to handle separately, but still had the semblance of the overall task. Did you track the completion of this task in any way to ensure that no pieces were left undone, much like an algorithm keeps placeholders to trace a way back from a recursive trajectory? If so, how did you do it? If not, why did you not?
Side Note: Here is the reason we discuss recursion for an IT degree. Recursion is the basis of searching and sorting...here is a quote from the following website (http://www.sparknotes.com/cs/recursion/examples/summary.html)
Next we'll look at how recursion can be used in searching and in sorting to increase the efficiency of these operations. Then we'll look at how recursion can be used for certain mathematical problems, such as printing a number in different bases and computing different sequences of numbers. For most of these problems, recursion presents an incredibly elegant solution that is easy to code and simple to understand.
Recursion may be difficult to understand at first, but once you do it becomes a powerful programming tool.
5. Given this recursive algorithm for computing a factorial...
procedure factorial(n: nonnegative integer)
if n = 0 then return 1
else return n *factorial(n − 1)
{output is n!}
Show all the steps used to find 5!

View Full Posting Details