Computer Science, asked by bhargavireddyb24, 4 months ago

Write an algorithm for printing a string 10 times?

Answers

Answered by harshithapalat11
1

Answer:

As an algorithm is a solution to a problem, we will characterize the problem as “The printing 10 times problem”. And thus the algorithm is “The correct way to solve The printing 10 times problem”. This algorithm has multiple parts.

Start -> Becomes ready to accept an input, this can happen via opening a port on an input digest of some kind, compiling a method with an input parameter, setting up a watcher or reader to read a piece of memory like a keyboard interrupt, ethernet device, etc.

Receive Input -> In the preferred input mechanism used, a value, preferably an ordered sequence of characters, must be made available for consumption. This can take the form of sending an HTTP request, typing in at a console prompt, having a method be called, etc.

Test Input -> In this part we verify that not only is the input a sequence of characters, but that these characters are composed of letters/symbols related to the language of choice. For some languages, this makes certain accented characters or symbols valid that would not exist in other languages. We do that by verifying that the numeric data value that corresponds to each of the characters in the table related to the encoding scheme, character set, and language is one of the acceptable values by iterating through the sequence or confirming in parallel. The iteration can occur by using loops or recursion, whereby we have a place for the Beginning of the input test, and a condition that determines whether or not we go back to the beginning of the input test or continue to the next step of the algorithm. The loop or the recursion would end up as some form of a simple GoToBeginning if the end of the sequence is not yet reached and use the next character in the sequence. To use the next character in the sequence, we can either pop off the current character and pull in the next character, or mathematically add the correct amount to the current index on the sequence. To confirm in parallel, we would create as many threads as there are characters, which would basically be queued as separate messages waiting for an available processor, send them out, and collect the responses. Once all responses were received, if any failed the check, then we would consider the input not a valid name. As we still need to print the sequence, if correct, we should take care not to destroy the memory in which the sequence is contained.

Begin Print -> Then, we create a loop/recursive call/parallel threads that will run at least ten times and at most ten times. The loop/recursive call will be restricted by some kind of a variable being set to an initial value and then mathematically incremented by a set amount, like one, each time in the loop until it reaches an amount that is ten times that set amount plus the initial value. Yes, it could also have been done by starting at a larger initial value then decrementing by a set amount until a smaller end value is reached. Inside of that loop/call, or for each of those threads, we then send the sequence to a print function of some kind. This print function, may write to a memory buffer that is assigned by the Operating System and is periodically scanned and flushed with whatever it’s contents are. This flushing can be linked up to a device like a monitor, or a hard drive, or an external printer, which will cause the message of what is in the print to be placed on a bus and sent to that device. The details are fairly complicated and probably outside of the scope of this algorithm.

TLDR: Loop ten times calling a print function with the name as a string. (Not an algorithm, does not compute/calculate/solve/provide more information/analyze/meaningfully address any kind of informational display problem/etc.).

Explanation:

Similar questions