当前位置:网站首页>Using C language to realize palindrome number

Using C language to realize palindrome number

2022-07-05 17:05:00 Daily study of bald girls

use C Language implementation palindromes

LeetCode Brush problem Day 1
subject : Enter an integer x , If x Is a palindrome integer , return true ; otherwise , return false .
Topic link :https://leetcode-cn.com/problems/palindrome-number/

Palindrome number concept :
Palindrome number refers to From left to right 、 From right to left Are the same integer .
Such as :343,232,898,123321 All palindromes ;
221,987,456,98765 Not even palindromes .

The code is as follows :

#include<stdio.h>
bool huiwenshu(long int x)   // Palindrome number judgment function 
{
    
    long int s,y=0;
    s=x;
    while(s>0)
    {
    
        y=y*10+s%10;
        s=s/10;  
    }
    if(y==x)
        return true;   // If it is a palindrome number, it returns 1
    else
        return false;  // If it is not a palindrome number, it returns 0
}
int main()
{
    
    long int number;  
    scanf("%d",&number);
    bool flag = huiwenshu(number);
    printf("%d\n",flag);
}

take number Defined as long int Type or long long int Type can be submitted successfully , Defined as int Type will overflow .
Running results :
If it is the palindrome number, it will output 1, If not, it is 0.
 Insert picture description here

 Insert picture description here

原网站

版权声明
本文为[Daily study of bald girls]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140510252380.html