Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next

 
Rand() function seeded srand(time(0)
Reply
Posted 2004-11-07, 01:14 PM
I know how to make a bubble sort and the exchange sort but I do not know how to generate a small arrays of dimension 20, such that the entries are random positive integers less than 100. I am also not sure if I can combine the bubble, exchange and sort the random array of integers. Heres what I have so far:

Bubble Sort:
Code:
#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);
}

Last edited by WetWired; 2004-11-08 at 07:01 AM. Reason: Please use the [code] tag
Old
Profile PM WWW Search
deadlock75 is neither ape nor machine; has so far settled for the in-betweendeadlock75 is neither ape nor machine; has so far settled for the in-between
 
deadlock75
 



 

Bookmarks

« Previous Thread | Next Thread »

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

Posting Rules [Forum 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


All times are GMT -6. The time now is 03:08 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.