Check Number is Palindrome or Not C++

本文介绍了在C++编程中判断一个数是否为回文数的方法。先让用户输入一个数,然后将该数反转,通过比较反转后的数与原数是否相等来判断是否为回文数,并给出了相应的C++代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Check Palindrome or Not in C++

To check for palindrome i.e., whether entered number is palindrome or not in C++ programming,

you have to first ask from the user to enter a number.

Now to check whether the entered number is a palindrome number (if reverse of the number is equal to its original) or not a palindrome number

(if reverse of the number is not equal to its original), you have to first reverse the number and check whether reverse is equal to original or not.

If it is equal then the number is palindrome, otherwise not palindrome number as shown here in the following program.

C++ Programming Code to Check Palindrome or Not

Following C++ program ask to the user to enter a number to reverse it, then check whether reverse is equal to its original or not,

if it is equal then it will be palindrome else it will be not be palindrome:

#include <iostream>

using namespace std;

int main()
{

//
int num, rem, orig, rev=0;
cout<<"enter a number: ";
cin>>num;

//
orig=num;
while(num!=0)
{

//
rem=num%10;
rev=rev*10+rem;
num=num/10;
}

//
if(rev==orig)
{
cout<<"Palindrome";
}

//
else
{
cout<<"Not Palindrome";

}
return 0;



}

Xfer from : https://codescracker.com/cpp/program/cpp-program-palindrome-number.htm

转载于:https://www.cnblogs.com/poission/p/10909802.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值