C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 11th, 2004, 06:11 PM
deadlock75 deadlock75 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 deadlock75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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);
}

Reply With Quote
  #2  
Old November 11th, 2004, 06:41 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
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-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Need help put it together


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT