Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is that homework?
Try to think how you would find the greatest and smallest number yourself if you were the computer and I presented the numbers one by one. Would you write them down or would you use another trick?
No it wasnt an assignment. i just did the commands of linux and was doing questions with my friends , then we thought how to do find for this question without using array. i thought of doing it with two for loops but wasnt able to chalk out. even with sort command but not getting properly. If possible , please help me
Ok, the way I would do it is have one loop that reads in the numbers one at a time: after reading each number check to see if it is larger than the largest read so far, or smaller than the the smallest so far: if it is store it. The main advantage to this approach is that you only ever have to store two numbers: regardless of how many numbers you are supposed to compare: be it 5 or 5 million.
Cheers,
Evo2.
PS. Notice that the point of the exercise is about algorithms not implementation.
Last edited by evo2; 12-16-2009 at 06:19 AM.
Reason: PS. + typo
thanks a lot
but may i know whats the last "head -1" in piping.
sorry i am a novice
and code i have submitted above , can i modify it to get the answer i want. i again tried not getting.
My logic is
Take first number & equate it to variables big & small.Now take next 4 numbers one by on & if currently entered number is > big then overwrite current on big.Similiarly if current number < small then overwrite on small.This is simple & obvious.After 5 numbers have been entered you have greatest in big & minimum in small.
If you find this post useful then thank me by pressing thumbs up button.Thank you.
Last edited by sumeet inani; 12-16-2009 at 09:10 AM.
'Incomplete cmd' sounds like you're typing that in at the cmd line. You need to put it in a script and execute that. If it doesn't work, post the script (in code tags)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.