| | |
Numbers in descending order(HELP)!
Thread Solved |
Hello Once Again..... I need you to help me with this program im working. My teacher asked me to create a program that could arrange the random numbers from lowest to highest.... but I can't follow up what's next in my program:
Is The 2nd loop correct????
C Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> int main() { int a,b[10]; for(a=1,a<=10,a++) { printf("Enter Number %d",a); scanf("%d",&b[a]); } for(b=0,b<=a,b--) { printf("The Numbers in Descending order:%d\n",b[a]) } return 0;
Is The 2nd loop correct????
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
LOVE YOU ALL!!!
your desciption indicates that you will be given a list of random numbers that will be in no particualr order. thus you cannot just loop through the array backwards. You will need to perform some form of sorting algorithm such as a Bubble Sort
Chris
Chris
Knowledge is power -- But experience is everything
Firstly...
is wrong.As you can see you are starting b's count from 0 and doing a b-- operation.
Secondly...
You need some sorting mechanism to sort your arrray.The simplest to understand may be selection sort to start with.
C Syntax (Toggle Plain Text)
for(b=0,b<=a,b--) { printf("The Numbers in Descending order:%d\n",b[a]); }
Secondly...
You need some sorting mechanism to sort your arrray.The simplest to understand may be selection sort to start with.
I Surf in "C"....
•
•
Join Date: Dec 2007
Posts: 17
Reputation:
Solved Threads: 1
Well, a simple logic for u is that
1. maintain loop which will run until a condition occurs ( that condition i will tell u a bit later)
2. now in that while loop read the first two number, if the 2nd one is greater than one than swap both number and place in the array again, do the same for 2nd and 3rd elements, and continue doing it until the end of the array.
3. The array will not be sorted on first iteration, we have to continue swapping the elements of array till it will have been sorted in descending order
4. Now lets talk about the condition of while loop, take a variable, and the value of this variable resets to 0 with the start of while loop, and the value of that variable, say x, gets incremented when there is a swapping occur in the whole list. So your while loop will stop if the value of variable x is 0 at the end of any iteration.
This is a slow and time taking algorithm, but its easy to understand. I will provide u the code if u need
1. maintain loop which will run until a condition occurs ( that condition i will tell u a bit later)
2. now in that while loop read the first two number, if the 2nd one is greater than one than swap both number and place in the array again, do the same for 2nd and 3rd elements, and continue doing it until the end of the array.
3. The array will not be sorted on first iteration, we have to continue swapping the elements of array till it will have been sorted in descending order
4. Now lets talk about the condition of while loop, take a variable, and the value of this variable resets to 0 with the start of while loop, and the value of that variable, say x, gets incremented when there is a swapping occur in the whole list. So your while loop will stop if the value of variable x is 0 at the end of any iteration.
This is a slow and time taking algorithm, but its easy to understand. I will provide u the code if u need
Yeah...it really takes a long time to finish it.... I barely got the half of it.... anyways I got a fair grade of trying.... but sir still didn't gave us the answer... but I will try your advice on swapping the arrays.... but before I ask for your code I'll have to try my best on this one...... you can give me your code and I'll try to study It on my own..... I really appreciate your help.... ^^
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
LOVE YOU ALL!!!
•
•
•
•
Solution has been sent to you ... however i didnt compile the code, but it will work, i just forgot to set the boundries of array and hope that u will do it by using a nested while loop of if condition, when u try yourself.
Have a happy programming
Secondly, code solutions are best in the thread they are the solution for. So in the future people are able to search for solutions to problems and find it. Rather than having to start a new topic, waste more peoples time purely because some goon wouldn't share a solution.
Chris
Last edited by Freaky_Chris; Jan 30th, 2009 at 6:20 am.
Knowledge is power -- But experience is everything
I have read the bubble sort but may I ask you what does beside of n ( := ) do?? I got this example in wikipedia....
C Syntax (Toggle Plain Text)
n := length( A ) do swapped := false n := n - 1 for each i in 0 to n - 1 inclusive do: if A[ i ] > A[ i + 1 ] then swap( A[ i ], A[ i + 1 ] ) swapped := true end if end for while swapped end procedure
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
LOVE YOU ALL!!!
![]() |
Similar Threads
- help with : sorting elements of array while preserving its index numbers (C++)
- descending bucket sort in 68000 (Assembly)
- overloading operator [] (C++)
- Random number with ascending order help (C++)
- help with descending sort program (C++)
- Small problem with command line (C)
- i need help with arrays (Java)
Other Threads in the C Forum
- Previous Thread: Date function in C
- Next Thread: converting a 1D array into a 2D array in C
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking highest homework i/o inches include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming socketprogramming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h





