Hi ,
PLease tell me the logic to find teh biggest of n numbers without using any functions.
Biggest of N numbers
Moderators: dbzTHEdinosauer, Moderator Group
Biggest of N numbers
Thanks and Regards,
Prashant
Prashant
Answer
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.
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.
-
- Member
- Posts: 7
- Joined: Sun Feb 05, 2006 9:31 am
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
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
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
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page