Write pseudocode that will generate a list of numbers from 1
Write pseudocode that will generate a list of numbers from 1 to 100 that are only multiples of 3. Try and do this without resorting to abstract statements! HINT: There is a built-in operation in Java that can calculate remainders – find it.
Solution
1. % This program generates list of numbers between 1 and 100 that are only multiples of 3.
2.
3. N = 100; % Maximum value to test
4. nums_db_3 = []; % Start with empty list
5. % Loop to test all numbers 1 to N
6. for n = 1:N
7. % Test divisibility of n by 3
8. % If divisible by 3, add to list
9. if mod(n,3) == 0
10. nums_db_3 = [nums_db_3; n]; % adding to list
11. end % end of if
12.
13. end % n loop
14.
15. % Print list
16. pnums

