Quiz 8 Solution - count_spaces( str ): set k to 0 set...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Name: _____________________________ Quiz Eight Write an algorithm for a function that counts the number of spaces in a string. The function has one parameter, a string, and returns the number of spaces in the string as output. The pseudocode has been started for you. The main function demonstrates how the count_spaces function might be called. [10 points]
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: count_spaces( str ): set k to 0 set spaces to 0 while str[k] != \0 do if str[k] == then set spaces to spaces + 1 set k to k + 1 return spaces end main: set s to one two three set count to count_spaces(s) print count //This should print 2 end...
View Full Document

This note was uploaded on 08/29/2011 for the course CIS 209 taught by Professor Aren during the Spring '11 term at Kansas State University.

Ask a homework question - tutors are online