C++ examples for Statement:for
A program to determine if a 5 digit integer is a palindrome
#include <iostream> bool isPalindrome(int); int main(int argc, const char *argv[]) { int num = 0;//w w w. ja va 2 s. c om std::cout << "Enter a 5 digit integer: "; std::cin >> num; printf("%d is%sa palindrome\n", num, (isPalindrome(num)) ? " " : " not "); return 0; } // check if number is a palindrome bool isPalindrome(int num) { if ((num / 10000) == (num % 10)) { num /= 10000; num /= 10; if ((num / 10) == (num % 10)) { return true; } } return false; }