2008 Apr 11 1:46 PM
hi,
can anyone send me the program for palindrome for a string and also for numbers..
its urgent
thankyou,
hai
sarvesh,
This is one of the logic to find the palendrom.
1. Find the Length of Given string using strlen.
2. Take n = 1 . len = strlen ( string).
len1 = len.
3. Using a Loop based on condition: n le len / 2.
3.1 Check if a[n] = a[len1].
3.2 if true
flag = 'y'.
else.
flag = 'n'.
endif.
3.3 n = n + 1. len1 = len1 - 1.
4. After the end of loop
if flag = 'y'.
write 'palendrom'.
else.
write ' not palendrom'.
endif.
I hope that, this is very simple logic and is very easy to convrt into program.
if useful, reward points.
Thank you,
G.V.K.Prasad
2008 Apr 11 1:49 PM
2008 Apr 11 1:55 PM
Hi,
This is a bit of a broad spec!
Do you want a program to generate palindromes?
Or do you want it to check if a string is a palindrome?
Does it need to check if they are proper words?
And if so what language?
Regards,
Nick
P.S. I don't have such a program, and if I needed one I don't think ABAP would be my first choice of language
2008 Apr 11 6:06 PM
i would like to check whether the string is palindrome or not? and i would like to use ABAP to do this,... do u have any program? if so send it to me for my reference.
2008 Apr 12 9:11 AM
Here's pseudo code - easy to convert to ABAP
pos_end = length of string
pos_start = 1
do pos_end/2 times.
read character of string at position pos_start and pos_end.
not the same?
set flag
exit
add 1 to pos_start
subtract 1 from pos_end
enddo.
if flag set
say 'not palindrome'.
else
say 'palindrome'
2008 Apr 11 2:02 PM
2008 Apr 12 4:07 PM
hai
sarvesh,
This is one of the logic to find the palendrom.
1. Find the Length of Given string using strlen.
2. Take n = 1 . len = strlen ( string).
len1 = len.
3. Using a Loop based on condition: n le len / 2.
3.1 Check if a[n] = a[len1].
3.2 if true
flag = 'y'.
else.
flag = 'n'.
endif.
3.3 n = n + 1. len1 = len1 - 1.
4. After the end of loop
if flag = 'y'.
write 'palendrom'.
else.
write ' not palendrom'.
endif.
I hope that, this is very simple logic and is very easy to convrt into program.
if useful, reward points.
Thank you,
G.V.K.Prasad
2008 Apr 13 10:27 AM
2012 Jul 03 10:34 PM
Heii,
I too was going through the same Homework stuff....wanted to make it more lucid...as used in the other languages...i guess using the string reverse is a better option...but just to make it fundamental...here is the coding I did...
parameters: p_input type string.
data: len type i,
len2 type i,
counter type i,
index type i.
len = strlen( p_input ).
len2 = len - 1.
do len times.
if p_input+index(1) = p_input+len2(1).
counter = 1.
else.
counter = 0.
endif.
len2 = len2 - 1.
index = index + 1.
enddo.
if counter = 1.
write:/ 'Palindrome Number'.
else.
write:/ 'Not a palindrome number'.
endif.
The results are accurate and tested.
Sumit
2022 Jul 12 7:07 AM
2012 Jul 04 5:51 AM
Hi,
DATA : in(50) TYPE c,
rev(50) TYPE c.
PARAMETERS Input TYPE string .
in = input .
CONDENSE IN .
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = in
lang = sy-langu
IMPORTING
RSTRING = rev
* EXCEPTIONS
* TOO_SMALL = 1
* OTHERS = 2
.
IF in EQ rev.
WRITE : ' THE STRING IS A PALINDROME ' .
ELSE .
WRITE : ' THE STRING IS NOT A PALINDROME ' .
ENDIF.
Thanks,
Dhivya.
2022 Jan 29 3:35 AM
"Program to check a palindrome string
class palindrome DEFINITION.
public SECTION.
class-methods: is_palindrome IMPORTING value(im_number) type String
RETURNING VALUE(result) type string.
endclass.
class PALINDROME IMPLEMENTATION.
method IS_PALINDROME.
"Check how many digits
Data(lv_lenght_number) = strlen( im_number ).
data(lv_count_loop) = lv_lenght_number div 2.
subtract 1 from lv_lenght_number.
"you can not use offset directly on importing parameter
data(lv_number) = im_number.
data(lv_counter) = 0.
while lv_count_loop ne 0.
data(lv_digit_from_left) = lv_number+lv_counter(1).
data(lv_digit_from_right) = lv_number+lv_lenght_number(1).
if lv_digit_from_left eq lv_digit_from_right.
add 1 to lv_counter.
subtract 1 from lv_lenght_number.
else.
result = 'Not a palindrome'.
exit.
endif.
result = 'Yes,it a palindrome'.
subtract 1 from lv_count_loop.
endwhile.
endmethod.
endclass.
START-OF-SELECTION.
data : result type string.
palindrome=>IS_PALINDROME(
EXPORTING
IM_NUMBER = 'abababa'
RECEIVING
result = result
).
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |