Explore BrainMass
Share

# Codes and Symbols

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Could you explain or convert each of the code , symbols used in the following solution?
For example what would "i\$" mean for me?
i=1 TO LEN(i\$) etc
What would j mean for me? etc
i + 1 TO 1 STEP - 1 etc
MOD 3) = 0 THEN PRINT MID\$(i\$, i, j) etc

Given a string of numbers, identify all of the substrings that form numbers that are divisible by 3. For example, applying the algorithm on the string 37540 should produce the following substrings (not necessarily in this order): 0; 3; 75; 54; 375; 540

1 i\$ = "37540" 'input string
2 FOR i = 1 TO LEN(i\$) 'loop from 1 to the length of the input string
3 FOR j = LEN(i\$) - i + 1 TO 1 STEP -1
4 'loop from the lenght from this point in the string to the end, down to 1
5 IF (VAL(MID\$(i\$, i, j)) MOD 3) = 0 THEN PRINT MID\$(i\$, i, j)
6 'using the modulo function, we check if the particular number is
'evenly divisible by 3
7 NEXT j 'end looping
8 NEXT i 'end looping

For example: 5469
5+4+6+9=24
2+4=6
therefore 5469 is evenly divisible by 3 or 5469 MOD 3 = 0

https://brainmass.com/computer-science/pseudocode/codes-symbols-110615

#### Solution Preview

Explanation

i\$ is a string,
LEN(i\$) is length of the string,
if i\$ = "37540"
Len(i\$) is 5

so For i = 1 to Len(i\$) means

i is an integer and it is initialized to 1
and it loops from 1 to 5 increasing i value each time by 1

In the loop there is another loop
FOR j = LEN(i\$) - i + 1 TO 1 STEP -1
means j is an integer which is initialized to 5 - ...

#### Solution Summary

Codes and symbols are explained.

\$2.19