/* this one is a bit more complex. It can count in both directions, and that isn't always useful. */ #include "library.h" /* start and end specify the range of numbers to be counted, and don't change as the function is doing its job. X records what point it is at now. It is a bit annoying because look at main, it doesn't seem reasonable to have to say the 30 twice. */ void count_from_to(int start, int end, int x) { if (start<=end) { if (x<=end) { print(x); newline(); count_from_to(start, end, x+1); } } else { if (x>=end) { print(x); newline(); count_from_to(start, end, x-1); } } } void main() { count_from_to(30, 10, 30); } /* That version evolved easily from where we were before, but with hindsight we can make something nicer: */ void count_from_to(int start, int end) { print(start); new_line(); if (startstart) count_from_to(start-1, end); } /* That got rid of the pesky X */