Write a C program to input number from user and check number is palindrome or not using while loop.
#include <iostream>
#include <algortihms>
#include <string>
int main() {
int number;
std::cin >> number;
std::string str = to_string(number);
int n = std::strlen(str) - 1;
int flag = true;
for (int i = 0; i <= n; i++) {
if (str[i] != str[n-i]) flag = false;
}
if (flag) std::cout << "The number is a palindrome" << std::endl;
else std::cout << "The number is not a palindrome" << std::endl;
return 0;
}
Comments
Leave a comment