✔ 最佳答案
#include <stdio.h>
#include <stdlib.h>
char str[256]="";
int numpal(int begin, int end)
{
if ( begin == end ) {
return 1;
} else if ((end - begin) == 1) {
return (*(str + begin) == *(str + end));
} else if (*(str + begin) == *(str + end)) {
return numpal(++begin,--end);
} else {
return 0;
}
}
int main()
{
int i, done;
printf("Check program for numeric palindrome.\n");
printf("Please enter a number to be checked or a negative number to end.\n");
done = 0;
while (!done) {
printf("Enter a number\n");
scanf("%s", str);
i = atoi(str);
if (i < 0) {
done = 1;
} else {
if (numpal(0, strlen(str)-1)) {
printf("%s is a numeric palindrome\n", str);
} else {
printf("%s is not a numeric palindrome\n", str);
}
}
}
return 0;
}