/* recursion.c - examples of recursion */

#include <stdio.h>

int SumNormal(int max)
{
	int sum = 0;
	printf("\tSumNormal(%d) - entered\n", max);
	while(max > 0)
		sum += max--;
	return sum;
}

int SumRecursive(int max)
{
	printf("\tSumRecursive(%d) - entered\n", max);
	if(max > 0)
		return max + SumRecursive(max - 1);
	else
		return 0;
}

int main(void)
{
	printf("SumNormal(10) yields %d\n", SumNormal(10));
	printf("SumRecursive(10) yields %d\n", SumRecursive(10));
	return 0;
}

/* exercises:
 * recursion in most cases can be reduced to iteration, and often
 * vice-versa.  try:
 * - a recursive function to print 0 through 10 (on number per iteration)
 * - a recursive function to output an array of chars using putchar and
 *   the address of the current character
 */

