Answer to Question #275833 in C for Tania Akter

Question #275833

Write a C program to input number from user and check number is palindrome or not using while loop.


1
Expert's answer
2021-12-05T13:07:33-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS