Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Rothbauer
Palindromes
Commits
c4178402
Commit
c4178402
authored
4 years ago
by
David Rothbauer
Browse files
Options
Download
Email Patches
Plain Diff
Add new file
parents
Pipeline
#984
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
palindromes.cpp
+40
-0
palindromes.cpp
with
40 additions
and
0 deletions
+40
-0
palindromes.cpp
0 → 100644
+
40
-
0
View file @
c4178402
#include
<iostream>
#include
<stdio.h>
#include
<string>
using
namespace
std
;
int
largestP
=
0
;
int
num
=
0
;
int
maxNum
=
9999
;
bool
isPalindrome
(
int
num
)
{
string
s
=
to_string
(
num
);
int
maxIndex
=
s
.
length
()
-
1
;
for
(
int
i
=
0
;
i
<=
maxIndex
/
2
;
i
++
)
{
if
(
s
[
i
]
!=
s
[
maxIndex
-
i
])
{
return
false
;
}
}
return
true
;
}
int
main
()
{
for
(
int
a
=
0
;
a
<=
maxNum
;
a
++
)
{
for
(
int
b
=
0
;
b
<=
maxNum
;
b
++
)
{
num
=
a
*
b
;
if
(
isPalindrome
(
num
)
&&
num
>
largestP
)
{
largestP
=
num
;
cout
<<
"Found: "
<<
largestP
<<
"
\n
"
;
}
}
}
cout
<<
"
\n
"
<<
"Nasel: "
<<
largestP
<<
"
\n
"
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets