/*
* Print the numbers 1 - 10, recursively.
* Call this function with a parameter of 1.
*/
void PrintTen(int value)
{
if (value <= 10)
{
printf("%i\n", value);
PrintTen(value + 1);
}
}
/*
* Print the numbers 10 - 1, recursively.
* Call this function with a parameter of 1.
*/
void PrintTenRev(int value)
{
if (value <= 10)
{
PrintTenRev(value + 1);
printf("%i\n", value);
}
}
/*
* Print numbers from start to end, recursively.
* This is a general version of PrintTen above.
*/
void PrintNumbers(int start, int end)
{
if (start <= end)
{
printf("%i\n", start);
PrintNumbers(start + 1, end);
}
}
/*
* Print numbers (in reverse) from start to end, recursively.
* This is a general version of PrintTenRev above.
*/
void PrintNumbersRev(int start, int end)
{
if (start <= end)
{
PrintNumbersRev(start + 1, end);
printf("%i\n", start);
}
}
/*
* Return the length of a NUL-terminated string.
* The parameter must not be NULL.
*/
int rec_strlen(const char *string)
{
if (*string)
return 1 + rec_strlen(string + 1);
else
return 0;
}