# Find the Palindrome Numbers in a certain range.

Jan 27th, 2017
178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // Palindrome numbers in a certain range
2.
3. #include <iostream>
4. #include <string>
5.
6. using namespace std;
7.
8. int main() {
9.
10.     int begin, end, counter = 0;
11.
12.     cout << "\nBeginning point: "; cin >> begin;
13.     cout << "\nEnding point: "; cin >> end;
14.
15.     for (int i = begin; i <= end; i++) {
16.
17.         string currNum = to_string(i);
18.         int size = currNum.size();
19.         bool checker = true;
20.
21.         for (int j = 0; (j < size / 2) && checker ; j++) {
22.
23.             if (currNum[j] != currNum[(size - 1) - j])
24.                 checker = false;
25.
26.         }
27.
28.         // if (checker == false)
29.             // cout << "\n" << i << " is not palindrome." << endl;
30.
31.         if (checker == true) {
32.
33.             cout << "\n" << i << " is palindrome." << endl;
34.             counter++;
35.
36.         }
37.
38.     }
39.
40.     cout << "\nTotal palindrome numbers in this range(" << begin << " - " << end << "): " << counter << endl;
41.
42.     return 0;
43.
44. }
45.
46. // for java
47. /*
48. public void findPalindrome() {
49.
50.         for (int i = begin; i <= end; i++) {
51.
52.             boolean FLAG = true;
53.             String currNum = Integer.toString(i);
54.             int size = currNum.length();
55.
56.             for (int j = 0; j < size / 2 && FLAG; j++) {
57.                 if (currNum.charAt(j) != currNum.charAt(size - 1 - j))
58.                     FLAG = false;
59.
60.             }
61.
62.             if (FLAG == true) {
63.                 counter++;
64.                 System.out.println("" + i + " is a palindrome number.");
65.             }
66.
67.         }
68.
69. }
70. */
RAW Paste Data