Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a cobol program to display prime numbers between 1 to 100?

Answer Posted / chandrababu

Please use below code to display prime number between 1 and N


0001.00 IDENTIFICATION DIVISION.
0002.00 PROGRAM-ID. COBOL31.
0003.00 AUTHOR. DURGA400.
0003.01 DATA DIVISION.
0003.02 WORKING-STORAGE SECTION.
0003.03 77 VAR PIC 9(3) VALUE 2.
0003.04 77 NUM PIC 9(3).
0003.05 77 REM PIC 99.
0003.06 77 REM1 PIC 99.
0003.07 77 QNT PIC 99.
0003.08 77 CNT PIC 99.
0004.00 PROCEDURE DIVISION.
0005.01 ACCEPT NUM.
0005.13 PERFORM 100-PARA TEST AFTER UNTIL VAR > NUM.
0005.14 100-PARA.
0005.15 IF VAR = 2
0005.16 DISPLAY "PRIME NUMBER " VAR
0005.17 ELSE
0005.19 PERFORM 200-PARA VARYING CNT FROM 2 BY 1 UNTIL CNT >= VAR
0005.20 DISPLAY "PRIME NUMBER " VAR
0005.21 END-IF.
0005.22 COMPUTE VAR = VAR + 1.
0005.25 999-END.
0005.26 STOP RUN.
0005.27 HALT.
0005.28 200-PARA.
0005.29 DIVIDE VAR BY CNT GIVING QNT REMAINDER REM
0005.30 IF REM = 0
0005.31 COMPUTE VAR = VAR + 1
0005.32 GO TO 100-PARA
0005.33 END-IF.
****************** End of data ************


Regards,
Chandrababu

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to update data area in cobol 400 program?

981


Define perform?

932


What is redefine?

1118


Explain the syntax of redefine?

856


I like to know if possible to use %TRIM or any statement with prefiv "%" like RPG ile programs. thanks

2419


Explain the difference between search and searchall?

811


How to detect record is locked in cobol/400? What is the solution for that?

887


What is output procedure?

932


seqence numbers in cobol

3044


Explain the syntax of sort?

926


What are the types of perform?

944


What is the syntax of redefine?

890


Define redefine and its syntax?

914


Explain the input procedure?

881


What are fillers?

974