Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Palindrome numbers in a certain range
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int begin, end, counter = 0;
- cout << "\nBeginning point: "; cin >> begin;
- cout << "\nEnding point: "; cin >> end;
- for (int i = begin; i <= end; i++) {
- string currNum = to_string(i);
- int size = currNum.size();
- bool checker = true;
- for (int j = 0; (j < size / 2) && checker ; j++) {
- if (currNum[j] != currNum[(size - 1) - j])
- checker = false;
- }
- // if (checker == false)
- // cout << "\n" << i << " is not palindrome." << endl;
- if (checker == true) {
- cout << "\n" << i << " is palindrome." << endl;
- counter++;
- }
- }
- cout << "\nTotal palindrome numbers in this range(" << begin << " - " << end << "): " << counter << endl;
- return 0;
- }
- // for java
- /*
- public void findPalindrome() {
- for (int i = begin; i <= end; i++) {
- boolean FLAG = true;
- String currNum = Integer.toString(i);
- int size = currNum.length();
- for (int j = 0; j < size / 2 && FLAG; j++) {
- if (currNum.charAt(j) != currNum.charAt(size - 1 - j))
- FLAG = false;
- }
- if (FLAG == true) {
- counter++;
- System.out.println("" + i + " is a palindrome number.");
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement