Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 21st, 2005, 6:17 AM   #1
zzk
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 zzk is on a distinguished road
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?
zzk is offline   Reply With Quote
Old Mar 21st, 2005, 6:33 AM   #2
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 574
Rep Power: 5 Benoit is on a distinguished road
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
Benoit is offline   Reply With Quote
Old Mar 21st, 2005, 7:24 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
could be a full stop character, as to end the loop eg

while input != '.'
stuff
end while
Berto is offline   Reply With Quote
Old Mar 21st, 2005, 11:01 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Mar 21st, 2005, 11:35 AM   #5
Hockeyman
Programmer
 
Hockeyman's Avatar
 
Join Date: Jan 2005
Location: Vancouver, Canada
Posts: 60
Rep Power: 4 Hockeyman is on a distinguished road
Send a message via MSN to Hockeyman
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. ~

Hockeyman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC