IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How we do palindrome program in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
varunkrish

New User


Joined: 25 Sep 2007
Posts: 1
Location: India

PostPosted: Mon Jul 07, 2008 8:28 pm
Reply with quote

how we do palindrome program in cobol
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Jul 07, 2008 8:45 pm
Reply with quote

Code:


01 WS-PAL PIC X(3) VALUE 'WOW'


IF WS-PAL = FUNCTION REVERSE(WS-PAL) THEN
 DISPLAY ' PALINDROME'
ELSE
 DISPLAY 'NOT PALINDROME'
END-IF


ensure you remove the trailing spaces (if at all present ) before using the function ....
Back to top
View user's profile Send private message
shoumitra sutradhar

New User


Joined: 22 May 2008
Posts: 3
Location: pune

PostPosted: Tue Jul 08, 2008 2:45 pm
Reply with quote

DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WS-PALIND PIC X(15).

PROCEDURE DIVISION.
MAIN-LINE.
PERFORM 0010-ACCEPT THRU 0010-EXIT.
PERFORM 0020-EVAL THRU 0020-EXIT.
STOP RUN.

0010-ACCEPT.
ACCEPT WS-PALIND.

0010-EXIT.
EXIT.

0020-EVAL.
IF WS-PALIND(1:1) = WS-PALIND(15:1)
AND WS-PALIND(2:1) = WS-PALIND(14:1)
AND WS-PALIND(3:1) = WS-PALIND(13:1)
AND WS-PALIND(4:1) = WS-PALIND(12:1)
AND WS-PALIND(5:1) = WS-PALIND(11:1)
AND WS-PALIND(6:1) = WS-PALIND(10:1)
AND WS-PALIND(7:1) = WS-PALIND(9:1)
DISPLAY ' THE WORD ENTERED IS PALINDROME: ' WS-PALIND
ELSE
DISPLAY ' THE WORD ENTERED IS NOT PALINDROME:' WS-PALIND
END-IF.

0020-EXIT.
EXIT.

------------------------------------
Hope this helps you.
Regards
Back to top
View user's profile Send private message
Itanium

Active User


Joined: 22 Jan 2006
Posts: 114
Location: India

PostPosted: Tue Jul 08, 2008 4:28 pm
Reply with quote

shoumitra,
This will work only when a 15 Byte word is entered.

It wont work for words like wow,madam etc..

Thanks,
Sakkara
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top