English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

A worm is moving toward an apple. Each time it moves, the worm cuts the distance between itself and the apple by its own body length until the worm is close enough to enter the apple. The worm can enter the apple when it is within a body length of the apple.

2007-09-13 02:47:53 · 3 answers · asked by michelle_2275 1 in Computers & Internet Programming & Design

3 answers

variable distance to apple
variable number of moves
variable body length

while distance to apple > body length
move toward the apple 1 time by doing...
1) the variable distance to apple gets a new value which is the distance to apple minus body length
2) increment number of moves by 1
end while loop

Say "The worm reached the apple in " number of moves " moves"

That is extremely high-level pseudo code that makes the assumption that you are trying to determine the number of times the worm has to move. You can write pseudo code as general as you would like because it doesn't have to pertain to any specific language. It is just supposed to convey the general idea. You can tailor that code to be more specific or general, but you get the idea.

Good luck.

2007-09-13 05:36:30 · answer #1 · answered by stephene 3 · 0 0

Pseudocode is a code that refers to a programming language, but in terms of your problem. for example look at this Pseudocode of the function eat() for a human being:

void eat()
{
while( I'm_humgry)
{
takeFork();
takeFoodWithFork();
takeFoodToMouth();
}

}

Pseudocode represents in a very high level of abastarction a problem.... if you see I didn't specify how to take the fork or the food... in pseudocode you give a first approach to the solution of a problem before programming seriously.

BY!!

2007-09-13 02:54:15 · answer #2 · answered by Anonymous · 1 3

The above answer will fetch you a ZERO for your project assignment.
It is not that easy. May be you can contact an algorithm expert. Check websites like http://askexpert.info/

2007-09-13 03:33:00 · answer #3 · answered by Anonymous · 0 2

fedest.com, questions and answers