Well it is a massively recursive solution.
Here's your code with some additional diagnostic.
Code:
#include <stdio.h>
int palindrome(int start, int end, int count);
int fill_array(int arr[], int num, int start);
int check_array(int arr[], int num, int end);
int depth;
int maxDepth;
int main(void)
{
int count = 0, start, end;
printf("Enter start and end: ");
scanf("%d %d", &start, &end);
count = palindrome(start, end, count);
printf("Number of palindrome numbers = %d\n", count);
printf("Max recursive depth=%d\n",maxDepth);
return 0;
}
int palindrome(int start, int end, int count){
int array[9], counter;
int result;
if ( ++depth > maxDepth ) maxDepth = depth;
if(start > end){
result = count;
}else{
counter = fill_array(array, start, 0);
count += check_array(array, start, counter);
result = palindrome(++start, end, count);
}
depth--;
return result;
}
int fill_array(int arr[], int num, int start){
int result;
if ( ++depth > maxDepth ) maxDepth = depth;
if(num != 0){
arr[start] = num % 10;
result = fill_array(arr, num/10, ++start);
}else{
result = start;
}
depth--;
return result;
}
int check_array(int arr[], int num, int end){
int result;
if ( ++depth > maxDepth ) maxDepth = depth;
if(end == 0){
result = 1;
}else if(num % 10 != arr[end-1]){
result = 0;
}else{
result = check_array(arr, num/10, --end);
}
depth--;
return result;
}
And my results.
Code:
$ ulimit -s
8192
$ ./a.out
Enter start and end: 0 16000
Number of palindrome numbers = 259
Max recursive depth=16007
My machine allows 8MB of stack, but on a 1MB stack, 16K recursions allows only about 64 bytes of stack space. With 40 bytes simply for the local variables of palindrome, and the parameters of all the functions, you're pretty close to 64 bytes per stack frame.
Since the values are small, you could just store an array of chars, or even an array of nibbles (with a bit more code effort).