该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
int Stringlong(char *string)
{
int length=0;
while(*string++!='\0')
{
length++;
}
return length;
}
int Palindrome(char *palindrome)
{
char prompt[50];
int number,a,b;
number=Stringlong(palindrome);
b=number-1;
if(number==1)
{
printf("This number is Palindrome!");
}
else if(number>1&&number%2==0)
{
for(a=0;a<=number/2-1;a++)
{
if(palindrome[a]==palindrome[b])
{
char prompt[50]="This number is Palindrome!";
}
else
{
char prompt[50]="This number isnt Palindrome!";
break;
}
--b;
}
puts(prompt);
}
else if(number>1&&number%2!=0)
{
for(a=0;a<=number/2;a++)
{
if(palindrome[a]==palindrome[b])
{
char prompt[50]="This number is Palindrome!";
}
else
{
char prompt[50]="This number isnt Palindrome!";
break;
}
--b;
}
puts(prompt);
}
return 0;
}
int main()
{
int i,j,k;
char huiwenshu[50];
puts("Please input a number to check if a palindrome:");
gets(huiwenshu);
k=Stringlong(huiwenshu);
if(k==1&&47
{
printf("This number is Palindrome!");
}
else if(huiwenshu[0]!='0'&&k>1)
{
for(i=0;i<51;i++)
{
if(huiwenshu[i]<58&&huiwenshu[i]>47&&huiwenshu[i]!='\0')
{
j=1;
}
else
{
j=0;
printf("ERROR!");
break;
}
}
if(j==1)
{
Palindrome(huiwenshu);
}
}
else
{
printf("ERROR!");
}
getch();
}