pseudo-code in C added.