Purpose: Getting Better at speaking with Program
Problem: Find the sum of all even numbers below 20
- Try writing the language to be spoken with program
- manual:
2+4+6+8+10+12+14+16+18
-
What does program (Snake) knows
- How to allocate memory
- It know + – * / % < > <= => ==
- One memory location for index
- One memory location for result
- One memory location for maxValue
-
Language: Hi Snake , remember 1 and call it as index remember 0 and call it as result remember 20 and call it as maxValue
Import Location:: check if index%2 == 0 if yes add index to result now increment index (index = index +1) if index <= max Goto Import Location:: display result
Problem : Try to find number of letters which are repeated more than one and its count in the following Text
Hello World
o/p:
l = 3
o = 2
knows about : length []
- Solution:
Hi snake, remember Hello World and call it as message
start with index = 0 till index < length(message)
get message[0] and store it in temp
compare it with all the other locations and maintain count
if count is zero ignore and continue scanning
else print letter = count