{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Quiz 8 Solution - count_spaces str set k to 0 set spaces to...

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.
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

{[ snackBarMessage ]}

Ask a homework question - tutors are online