- 1

A palindrome program

6th Oct 2016, 4:32 AM
Mohammed Asif
Mohammed Asif - avatar
2 Answers
0
Cool story Bro.
6th Oct 2016, 10:03 PM
Xaviera Yayaell
Xaviera Yayaell - avatar
0
For checking both strings and numbers: https://code.sololearn.com/cEsM6xGQ46kY/#cpp #include <iostream> #include <string> #include <cstring> using namespace std; void checkIfPalindrome(string s) { int low = 0; int high = s.length() - 1; while (true) { char a = s[low]; char b = s[high]; if (low > high) { cout << s << " IS a palindrome" << endl; return; } if (a == b) { low++; high--; } else { cout << s << " IS NOT a palindrome" << endl; return; } } } void checkIfPalindrome(long i) { long n = i; long reverse = 0; while (n != 0) { reverse *= 10; reverse += +(n % 10); n /= 10; } if (i == n) { cout << i << " IS a palindrome" << endl; } else { cout << i << " IS NOT a palindrome" << endl; } } int main() { checkIfPalindrome("ABCBA"); checkIfPalindrome("AVBES"); checkIfPalindrome("12321"); checkIfPalindrome("94523"); return 0; }
6th Oct 2016, 11:35 PM
Liam
Liam - avatar