Previous Slide Example Program Run Next Slide

A run of this program might look like:
% scramble
Enter a string to scramble (enter no spaces and no more
than 80 characters).

String? articulate

Now enter pairs of numbers representing positions to swap
to create the scrambled version (e.g., "1 3").  Positions are
numbered between 1 and 10 for this string.  Enter "0 0" when
you are done.

Swap? 1 2
New scrambled version: raticulate

Swap? 2 3
New scrambled version: rtaiculate

Swap? 0 8
Positions must be between 1 and 10!

Swap? 10 7
New scrambled version: rtaicueatl

Swap? 0 0

The string: articulate
was scrambled to: rtaicueatl

Note that positions in the string start with 1 (as entered by the user to the program).


BU CAS CS - Scrambling a String - Lab
Copyright © 1993-2000 by Robert I. Pitts <rip@bu.edu> All Rights Reserved.