Biggest of N numbers

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
pkaushi
Member
Posts: 9
Joined: Mon Feb 06, 2006 1:45 pm

Biggest of N numbers

Post by pkaushi » Fri Feb 10, 2006 3:16 pm

Hi ,

PLease tell me the logic to find teh biggest of n numbers without using any functions.
Thanks and Regards,
Prashant

Guest

Answer

Post by Guest » Wed Apr 12, 2006 2:10 pm

Hi,

You can define a single variable of the maximum length. Assuming that all the N numbers that you have to search is around pic 9(6).

Move the first number to the defined variable.

So you do in an loop, till you have scanned all the N numbers. literally you may to do an loop of n-1 times.

If compare the second number number with the variable defined, if found to be bigger move the second number to the variable.

Similiarly do in an loop till you have looked at all the N numbers.


At the end the variable would have the highest number.

padmapriya7
Member
Posts: 7
Joined: Sun Feb 05, 2006 9:31 am

Post by padmapriya7 » Wed Aug 02, 2006 12:15 pm

using loop u can get it
1. assign one variable called it max
2. start loop to accept n numbers and end the loop
3. Again you start the loop
i. compare first element of the variable with max variable
if it is bigger assign that value to the max variable
repeat the end of the loop
endthe loop
note: table is the best way i think

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others