![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0
![]() |
Basic thing
Hi everybody,
I have a question regarding algorithms Read this algorithm Counter = 0 Input character While character is not a full stop do If character = space then Counter = Counter + 1 endif Input character endwhile Number = counter + 1 Output Number What is the output if the following is input? The holidays will soon be here I think there will not be any output since there is no full stop at the end and therefore, the while condition is not full filled. What do you think? |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4
![]() |
What do you mean by full stop? The null byte?
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
could be a full stop character, as to end the loop eg
while input != '.' stuff end while |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
I'd probably write the code the implements the algorithm and enter the text in as a parameter to ensure a correct answer.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Programmer
|
Assuming the full stop refers to a (non-displayed) null character at the end of the string, the output would be "6".
That algorithm loops through a string one character at a time, incrementing the counter between each word (as determined by spaces). When it reaches the null character (end of string) it exits the while loop and adds one more to the counter to account for the last word.
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~ read my blog @ My Lucky Rocketship Underpants
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|