Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
#include<stdio.h>

int palindrome(int n);

int main()
{
    int x;
    scanf("%d",&x);
    palindrome(x);
    return 0;
}

int palindrome(int n)
{
    int r,re=0;
    while(n !=0)
    {
        r=n%10; // remainder= the number modulus 10
        re=r+re*10;
        n=n/10;
    }
    if(n==re) // if the number is equal to the reverse number then it is
              // palindrome otherwise not palindrome.
        printf("Palindrome");
    else
        printf("Not Palindrome");
}

最佳答案

当您的代码到达while函数中的palindrome循环之外时,n的值已变为0,然后将其与re进行比较,该nn的反向版本,答案为“否”。每次回文,除非n的值是强文本本身。

你应该:


re的值复制到某个变量中,然后将其与re进行比较,而不是将nreturn进行比较。
palindrome函数的末尾放置一个虚拟。
评论回文,否则不回文。评论/部分。

07-24 09:45
查看更多