Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
keerthi

New User

Joined: 23 Mar 2005
Posts: 25

 Posted: Sat Jul 30, 2005 8:03 am    Post subject: interview questions Can anybody please send me the COBOL programs for the questions? 1. biggest of 10 numbers 2. Prime numbers between 1 and 100 thanks in advance.

mdtendulkar

Active User

Joined: 29 Jul 2003
Posts: 238
Location: USA

Posted: Sat Jul 30, 2005 8:31 am    Post subject:

keerthi,

Biggest of 10 numbers

Steps...

- Take all the 10 input numbers
- put it in a working storage table
- sort the table on number descending
- first instance is the biggest

Prime Numbers between 1 and 100

 Code: 000010 IDENTIFICATION DIVISION.  000020 PROGRAM-ID.    PRIME-NO-PROG.          000030 AUTHOR.        TIMOTHY R P BROWN. 000040    000050******************************************            000060* PROGRAM TO CALCULATE PRIME NUMBERS     *            000070******************************************            000080 000090 ENVIRONMENT DIVISION.      000100 INPUT-OUTPUT SECTION.      000110 FILE-CONTROL. 000120 000130       SELECT OUT-FILE ASSIGN TO 'PRIME-NO.TXT'      000140           ORGANIZATION IS LINE SEQUENTIAL.          000150********************************************    000160 DATA DIVISION.            000170 FILE SECTION. 000180 000190 FD OUT-FILE. 000200 01 NO-OUT      PIC X(80). 000210******************************************** 000220 WORKING-STORAGE SECTION.  000230 000240 01 EVEN-FLAG PIC X.        000250      88 NUM-EVEN VALUE 'Y'.            000260 01 PRIME-FLAG PIC X .      000270      88 IS-PRIME VALUE 'Y'.            000280 000290 01 TOP-VALUE  PIC 9(7) VALUE ZERO.      000300 000310 01 COUNTERS. 000320       03 Y-COUNT PIC 9(6) OCCURS 1000. 000330 000340 01 CALC-NO       PIC 9(6) VALUE ZERO.    000350 000360 01 SUBS.      000370      03 X-SUB    PIC 9(6) VALUE 3.    000380 01 PRINT-SUBS.            000390      03 P-COUNT-X  PIC 9(6) VALUE 1.    000400 000410 01 A       PIC 9(6) VALUE ZERO.        000420 01 B       PIC 9(6) VALUE ZERO.        000430 01 C       PIC 9(6) VALUE ZERO.        000440 01 D       PIC 9(6) VALUE ZERO.        000450 01 Z       PIC 9(6) VALUE ZERO. 000460 01 PRIME-NO-COUNT PIC 9(6) VALUE 2.  000465 000470 01 PRINT-LINE.            000480      03 P-NUM1  PIC Z(5)9 VALUE ZERO.  000490      03 P-NUM2  PIC Z(5)9 VALUE ZERO.  000500      03 P-NUM3  PIC Z(5)9 VALUE ZERO.  000510      03 P-NUM4  PIC Z(5)9 VALUE ZERO.  000520      03 P-NUM5  PIC Z(5)9 VALUE ZERO.  000530 000540 01 EXIT-KEY PIC X VALUE SPACE.            000545      000550*******************************************************    000560 PROCEDURE DIVISION.        000570 MAIN-PARA.    000580      OPEN OUTPUT OUT-FILE 000590      DISPLAY 'ENTER VALUE TO WHICH PRIME NUMBERS '  000600      DISPLAY 'ARE TO BE CALCULATED BETWEEN 1 AND 999,999' 000602      MOVE 1 TO Y-COUNT (1) 000605      MOVE 2 TO Y-COUNT (2)      000610 000620*ENTER VALUE  000630      PERFORM UNTIL TOP-VALUE > 0        000640      ACCEPT TOP-VALUE      000650      END-PERFORM          000660 000670*ZEROISE TABLE 000680      MOVE ZEROS TO COUNTERS            000690 000700*DETERMINE PRIME NUMBERS AND PLACE IN TABLE          000710 000720      PERFORM VARYING CALC-NO FROM 3 BY 1            000730    UNTIL CALC-NO > TOP-VALUE            000740         DISPLAY  CALC-NO          000750         MOVE 1 TO C        000760         MOVE 'N' TO PRIME-FLAG          000770 000780*IS NUMBER EVEN (BUT NOT 2)?  000790 000800         DIVIDE CALC-NO BY 2 GIVING A REMAINDER Z      000830         IF Z = 0 THEN MOVE 'Y' TO EVEN-FLAG          000840         ELSE MOVE 'N' TO EVEN-FLAG      000850         END-IF            000860            000865********************************************************** 000870*DIVIDE EACH ODD NUMBER BY NUMBERS UP TO HALF THE CALC-NO        000880*LOOP EXITED WHEN A NUMBER DIVIDES IT WITH NO REMAINDER            000890*OR WHEN ALL NUMBERS CHECKED 000895********************************************************** 000900         IF NOT NUM-EVEN THEN            000910            PERFORM VARYING D FROM 3 BY 1            000920    UNTIL (C = 0) OR (D > ((CALC-NO + 1) / 2))        000930  DIVIDE CALC-NO BY D GIVING A REMAINDER C            000940            END-PERFORM    000950         END-IF            000960 000970         IF C = 0 THEN MOVE 'N' TO PRIME-FLAG        000980         ELSE MOVE 'Y' TO PRIME-FLAG    000990         END-IF            001000 001010*WHEN PRIME NUMBER DEFINED, MOVE IT INTO TABLE        001020         IF IS-PRIME THEN  001030            MOVE CALC-NO TO Y-COUNT (X-SUB)          001040            ADD 1 TO X-SUB PRIME-NO-COUNT      001050         END-IF            001060      END-PERFORM          001070 001080*STORE THE FINAL VALUE OF X-SUB BEFORE RE-USING IT    001090      MOVE X-SUB TO P-COUNT-X            001100      MOVE ZERO TO X-SUB    001110***************************************************            001120*WRITE TABLE  001130      PERFORM VARYING X-SUB FROM 1 BY 5 001140            UNTIL X-SUB > P-COUNT-X      001150         MOVE Y-COUNT (X-SUB) TO P-NUM1 001160         MOVE Y-COUNT (X-SUB + 1) TO P-NUM2          001170         MOVE Y-COUNT (X-SUB + 2) TO P-NUM3          001180         MOVE Y-COUNT (X-SUB + 3) TO P-NUM4          001190         MOVE Y-COUNT (X-SUB + 4) TO P-NUM5          001200         WRITE NO-OUT FROM PRINT-LINE AFTER 2 LINE 001230      END-PERFORM          001240 001250      DISPLAY 'CALCULATIONS COMPLETE - ' PRIME-NO-COUNT            001260            ' PRIME NUMBERS CALCULATED' 001270      CLOSE OUT-FILE        001280      STOP RUN.

Hope this helps

Regards
Mayuresh
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics The Last Two Question For You To Ask ... CaptBill Mainframe Interview Questions 0 Fri Apr 14, 2017 5:42 am Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm Viewing executing process in NDM .. q... Debb.Brant IBM Tools 0 Wed Dec 14, 2016 10:55 pm INCLUDE condition questions van bui DFSORT/ICETOOL 1 Thu Jun 30, 2016 9:52 am SAS Programming - Basic Questions Techelm All Other Mainframe Topics 3 Fri Mar 18, 2016 10:53 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us