Learn to Program Step-by-Step

Salt and Pepper Algorithm

Salt and Pepper

In the illustration, the salt and pepper are in the wrong containers. The pepper is in the jar that says "Salt" and the salt is in the jar that says "Pepper."

salt and pepper reversedHow would you fix this problem?


  • Pour the contents of the salt shaker (the pepper) into the extra jar. step1
  • Pour the contents of the pepper shaker (the salt) into the salt shaker.
  • step2
  • Pour the contents of the extra shaker (the pepper) into the pepper shaker.
  • step2

    Tada!!! The salt is in the salt shaker and the pepper is in the pepper shaker. Mission accomplished.

    Now look at the pseudo code.

    Like us on Facebook:

    OER: Open Educational Resource
    Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
    Creative Commons Attribution-NonCommercial 4.0 International License
    Last modified: January 08 2016 10:54:07.