C++ Program to Check if Given Number is Palindrome or Not using While Loop
Write C++ Program to Check if Given Number is Palindrome or Not using While Loop
// CPP Program to Check if given number is palindrome or not using While Loop #include <iostream> using namespace std; int main() { long int n, ans = 0; cout << "Enter the number:--> "; cin >> n; //User input:-422 long int temp = n; while(n != 0) { int remainder = n % 10; //2 //2 //4 ans = ans * 10 + remainder; //2 //22 //224 n = n / 10; //42 //4 } if(temp == ans) { cout << "The given number is palindrome"; } else { cout << "The given number is not palindrome"; } return 0; }
Output:
Enter the number:--> 456
The given number is not palindrome
Enter the number:--> 121
The given number is palindrome