September 2, 2011

Example 7

Task:
Create a program to calculate the number of words.
Example:
Sentence: learn algorithm
Word count: 2


Code:
input sentence

isAnyWord<-F 
num<-0
for a<-1 to Length(sentence), a++
{
  if sentence[a]!= ' ' then isAnyWord <- T //if not space
  if sentence[a] = ' ' then //if space
  {
    if isAnyWord = T then //if previously there was a word, num++
    { 
      num++
      isAnyWord = F
    } 
  }
}

No comments:

Post a Comment