Different result evey this code is executed

I'm trying to find the biggest palindrome when two 3 digit numbers are multiplied.

Why is it that my code never display all the palindromes? Every times it runs, it gives me a different result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main() {
    for (int i = 100; i < 1000; i++){
        for (int j = 100; j < 1000; j++){
            int palindrome = i * j;
            std::string number = std::to_string(palindrome);
            int length;
            length = number.length();
            bool flag = true;
            for (int k = 1; k < length; k++){
                if (number[k] != number[length - k - 1]){
                    flag = false;
                    break;
                }
            }
            if (flag){
                std::cout << number << std::endl;
            }
        }
    }
    return 0;
}


thanks
Last edited on
can't reproduce
show an example output.
This is with last version of clion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
10201
11211
12221
13231
14241
15251
16261
17271
18281
19291
20402
21412
22422
23432
24442
25452
26462
27472
28482
29492
30603
31613
32623
33633
34643
35653
36663
37673
38683
39693
40804
41814
42824
43834
44844
45854
46864
47874
48884
49894
20502
21012
41514
42024
62526
63036
83538
84048
21012
26162
42024
47174
63036
68186
84048
89198
21112
27872
42224
48984
63336
80808
84448
88088
50505
53235
55755
58485
21412
23532

Process finished with exit code 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
10201
11211
12221
13231
14241
15251
16261
17271
18281
19291
20402
21412
22422
23432
24442
25452
26462
27472
28482
29492
30603
31613
32623
33633
34643
35653
36663
37673
38683
39693
40804
41814
42824
43834
44844
45854
46864
47874
48884
49894
20502
21012
41514
42024
62526
63036
83538
84048
21012
26162
42024
47174
63036
68186
84048
89198
21112
27872
42224
48984
63336
80808
84448
88088
50505
53235
55755
58485
21412
23532
25652
27772
29892
40704
42824
44944
25252
45154
65056
73937
93839
27972
29592
46764
48384
63936
65556
67176
82728
84348
15151
64746
74447
79897
84148
89598
99299
11211
12321
13431
14541
15651
16761
17871
18981
20202
21312
22422
23532
24642
25752
26862
27972
30303
31413
32523
33633
34743
35853
36963
40404
41514
42624
43734
44844
45954
50505
51615
52725
53835
54945
60606
61716
62826
63936
70707
71817
72927
80808
81918
90909
23632
29792
42224
48384
65856
84448
27572
49494
51415
73337
78987
80908
95259
26562
43434
60306
68286
69996
85158
86868
52325
53935
56465
21112
23432
25752
42224
44544
46864
61016
63336
65656
67976
82128
84448
86768
28782
30303
53235
60606
76167
83538
90909
99099
21712
25252
46964
64546
68086
82128
89798
15351
44744
54145
69496
83538
98889
12221
13431
14641
15851
22022
23232
24442
25652
26862
33033
34243
35453
36663
37873
44044
45254
46464
47674
48884
55055
56265
57475
58685
59895
66066
67276
68486
69696
77077
78287
79497
88088
89298
99099
106601
119911
26962
27572
28182
40504
41114
6
Process finished with exit code 0
Last edited on
Thanks! I did search before posting but didnt stumble on that link.
Topic archived. No new replies allowed.