writing algorithm isn't that much difficult. for e.g for the first program
step1: initialize the variables
step2: modulo divide the number by 10 so as to get the individual digits.
step3: save the number in a variable.
step4: divide the number by 10.
Like this u can move on and since it is in a loop, U specify that "follow these steps until u get a single digit" r u can even use goto <step number>.
This may not be the actual or proper algorithm for ur program. I just wrote it for an example.