Simplybestwinner
Simplybestwinner

Reputation: 1

Pseudocode what is the output?

I am finding it hard to find what this pseudocode outputs. Does it mean for example if you entered the name Peter. Would the output be pet? Or the letter t?

Display enter a name
Get name
Length = length of name 
Index = length -1 
While index >= 0 Do
      DISPLAY name(index)
      Index = index -2 
ENDWHILE

Upvotes: 0

Views: 703

Answers (1)

trincot
trincot

Reputation: 350996

It displays the letters in reverse order, skipping one every time. So Timothy gets displayed as ytmT.

Here is an implementation in JavaScript, which you can test:

var display = '';
var name = prompt("Enter a name:");
length = name.length; 
index = length - 1;
while (index >= 0) {
      display += name[index];
      index = index -2 
}
alert(display);

Upvotes: 0

Related Questions