Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 9th, 2004, 12:13 PM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
On this one I have no idea how to start.

I need to write program that will read a list of five numbers and returns them in increasing order.

First I will need to create my variables:

int a,b,c,d,e;

Then what, do I have to use the max and min to compare then I will create the output.

Thanks in advance.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 9th, 2004, 12:48 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
What you should do is use an array. You declare an array like this:

int array[5];

What that does is make an array of variables. In this case it can hold 5 different numbers. So lets say you store the following numbers in there:

5 10 25 17 6

To get the first number in the array you would call it like this

int x=array[0];

That would set x to 5. If you had put a [4] instead of a [0] then it would have stored 6 in x.

Then you can use a couple of for loops to sort them, like this:

 
    for(j=0;j<array[j];j++)
    {
        for(k=0; k<array[k+1];k++)
        {
            if(array[k]<=array[k+1])
            {
                int x = array[k];
                array[k]=array[k+1];
                array[k+1]=x;
            }
        }
    }

(Hope I didn't give away too much)

Look up couple of the sort algorithms. If you need me to go further into detail about arrays then I can.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 9th, 2004, 4:08 PM   #3
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Nice work, could it be done without using arrays.

Can we do it with using a loop only?
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 9th, 2004, 6:47 PM   #4
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
It can be done, but it would be a lot more work. Arrays make it a lot more effecient.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 9th, 2004, 7:30 PM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Why not try your homwork before asking sombody to do it for you so, you understand how the answer comes about?
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 10th, 2004, 2:27 AM   #6
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Quote:
Originally posted by Pizentios@Oct 9 2004, 11:30 PM
Why not try your homwork before asking sombody to do it for you so, you understand how the answer comes about?
I am not asking you to go my homework Pizentios, I only ask to help me out to gain the idea of developing it.

Also our lecturer has no idea of what he’s teaching, that way I had to come to find the support somewhere else and I am trying my best, its not only of doing the homework its Pizentios matter of learning something too.

And as i said I didnt know how to start, so i asked for some support.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 10th, 2004, 2:27 AM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Yes. Pizentios is correct... you have posted several homework questions it seems... most of which shows that you never made a valid attempt at a solution. You will learn a great deal in the analytical, problem-solving, logical/rational thought, development and debugging processes if you do your own work. I hate for one of use to "earn" your diploma or degree for you and you get to the field and don't know what you are doing. With that said, we are all here to help... just let us know that you have put forth the effort to derive a solution first.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Oct 10th, 2004, 3:09 AM   #8
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Well, I kind of think what he's asking. When you don't have any idea of the algorithm you're supposed to use then it's pretty hard to start off. For example, I prefer to do all my homework by myself, but on that mouse-cheese problem I didn't even know where to start, so I just posted the question to get an idea how to start, not really to get a definitive answer. The solution that I came up with took quite a bit of thinking, and was probably still a pretty crappy way to do it. Although, I do see what IR is saying, TecBrain. It is a lot more rewarding when you come up with a solution to a tough problem entirely on your own.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 10th, 2004, 11:13 AM   #9
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
I agree with you guys, you’re all right:

Infinite Recursion you said that “most of which shows that you never made a valid attempt at a solution.” That is not true, check all my posts.

Don’t forget guys that you are a programmer or at least with a good background programming skills, for me… let me see its my 2nd week of C++, so I don’t know have background knowledge.
And there is no way of me knowing how to think of how to order number in an increasing order…. That’s why I am here, I am not asking for writing the codes…..

Please don’t get me wrong….
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 10th, 2004, 11:47 AM   #10
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
TecBrain, I could be wrong, just seemed like you were posting one assignment after another... I don't have time to review the posts and gather statistics.

We are all here to help.... I spent 4 years in college and yes, I've had instructors that did not know what the hell they were doing and were very confusing. So I know why you are seeking outside assistance, which is very smart. Even some textbooks can be very confusing.

Divide and Conquer, process of elimination, trial-and-error are some of the best ways to hammer out a solution. You are right, if you are new to the field there will definitely be alot of questions. I just see too much of "do my homework and email it to me" type of posts here and at other sites.

As I said, we are all here to help... as long as you all let us know what you have tried or show some other sign of making a valid effort... I have no problem helping out.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC