| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help put it together
I am not sure what else to do, I am to post to use rand() (seeded with either srand(time(0)) or with randomize(), to generate a small arrays of dimsion 20, such that the entries are random positive integers less than 100. Then I have make sure to implement the bubble sort and the exchange sort and sort the random array of integers. This is what I have so far can someone help me finish this program? I really really need someone's help put it together I have tried many possiblities but they don't work together however I do it. But it works when it is separated.
#include <stdio.h> #include <windows.h> int main(){ srand(GetTickCount()); int randomNum; int i; for(i = 0; i < 50; i++){ randomNum = rand()%100 + 1; printf("%d\n", randomNum); } system("pause"); return(0); } Bubble Sort: #include <stdio.h> main() { int numbers[10], i, j, k, tmp; printf("\nthe original numbers are:\n"); for (i=0; i<10; i=i+1) { numbers[i]=rand(); printf(" %d ", numbers[i]); } printf("\n\n"); for (i=0; i<10; i=i+1) { for (j=0; j<9; j=j+1) { if (numbers[j]<numbers[j+1]) { tmp=numbers[j]; numbers[j]=numbers[j+1] numbers[j+1]=tmp; } } } printf("the sorted numbers are:\n") for (i=0; i<10; i=i+1) { printf(" %d ", numbers[i]); } printf("\n\n"); } Exchange Sort: #include <stdio.h> main() { int numbers[10], i, j, k, tmp; printf("\nthe original numbers are:\n"); for (i=0; i<10; i=i+1) { numbers[i]=rand(); printf(" %d ", numbers[i]); } printf("\n\n"); for (i=0; i<9; i=i+1) { for (j=0; j<10; j=j+1) { if (numbers[i]<numbers[j]) { tmp=numbers[j]; numbers[j]=numbers[i] numbers[i]=tmp; } } } printf("the sorted numbers are:\n") for (i=0; i<10; i=i+1) printf(" %d ", numbers[i]); printf("\n\n"); return(0); } |
|
#2
|
|||
|
|||
|
For starters please enclose your code in code tags so its better formatted. It gives everyone a much better chance of seeing where you are going wrong.
Plus tell us what does work and what doesn't. Give some examples of what happens. Just saying 'it doesn't work' doesn't give us many clues as to where your problem lies. -KM- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Need help put it together |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|