![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#4 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
It can be done, but it would be a lot more work. Arrays make it a lot more effecient.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#6 | |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Quote:
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. |
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#8 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#10 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|