These are very basic. It comes down to understanding numeric operations, conditionals and loops. The way you use the word algorithm indicates you are over thinking. (don't get too frustrated because that's a common issue with new coders).
There are two tricks that helped me "get it".
1) Use indentation to visually isolate the results of conditionals. Here are two examples (1 and 4):
Code:
example #1
N = 1234
D = 0
while N != 0
inc(D)
N = N div 10
end while
write "D = " D
Example #4
D = 0
N = 100
writeln D
writeln N
while D < N div 2
inc(D)
if N mod D == then
L = D
end if
end while
writeln L
write N
2) Write out the operations through the loop so you can follow it. Example #1 :
Code:
N = 1234
D = 0
while N != 0
inc(D)
N = N div 10
end while
write "D = " D
-----------------------------------------------
Beginning of Pass 1
N=1234
D=0
N (1234) IS NOT equal to zero so the while conditional will be true, and the loop will continue
D (0) is incremented so D (0) will equal D (0) + 1 or 1 in this pass
N (1234) is divided by 10 so now equals 123.4 and the result set back to N (the test instructions probably say to assume that all variables are integers which cannot have a decimal place so the .4 is truncated and ignored) N will thus equal 123
-----------------------------------------------
Beginning of Pass 2
N=123
D=1
N (123) IS NOT equal to zero so the while conditional will be true, and the loop will continue
D (1) is incremented so D (1) will equal D (1) + 1 or 2 in this pass
N (123) is divided by 10 so now equals 12.3 and the result set back to N (the test instructions probably say to assume that all variables are integers which cannot have a decimal place so the .3 is truncated and ignored) N will thus equal 12
-----------------------------------------------
Beginning of Pass 3
N=12
D=2
N (12) IS NOT equal to zero so the while conditional will be true, and the loop will continue
D (2) is incremented so D (2) will equal D (2) + 1 or 3 in this pass
N (12) is divided by 10 so now equals 1.2 and the result set back to N (the test instructions probably say to assume that all variables are integers which cannot have a decimal place so the .2 is truncated and ignored) N will thus equal 1
-----------------------------------------------
Beginning of Pass 4
N=1
D=3
N (1) IS NOT equal to zero so the while conditional will be true, and the loop will continue
D (3) is incremented so D (3) will equal D (3) + 1 or 4 in this pass
N (1) is divided by 10 so now equals .1 and the result set back to N (the test instructions probably say to assume that all variables are integers which cannot have a decimal place so the .1 is truncated and ignored) N will thus equal 0
-----------------------------------------------
Beginning of Pass 5
N=0
D=4
N (0) IS equal to zero so the while conditional will be false , and the loop terminate
the write statement create an output of "D = 4"
Hope that helps,
Dan