Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define SIZE 200
void sort(int *array, int size);
int rnd(int range);
void seedrnd(void);
void main()
{
int number[SIZE];
int x;
printf("Here is the array unsorted and random.\n");
seedrnd();
for(x=0;x<SIZE;x++)
{
number[x] = rnd(140)+1;
printf("%i\t",number[x]);
}
printf("\nPress enter to see the array sorted.");
getchar();
printf("\n");
sort(number, SIZE);
for(x=0;x<SIZE;x++);
printf("%i\t",number);
}
void sort(int *array, int size)
{
int a, b, temp;
for(a=0;a<SIZE-1;a++)
for(b=a+1;b<SIZE;b++)
if(array[a] > array[b])
{
temp=array[b];
array[b]=array[a];
array[a]=temp;
}
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
i understand the first part but what does this do??--
Code:
void sort(int *array, int size)
{
int a, b, temp;
for(a=0;a<SIZE-1;a++)
for(b=a+1;b<SIZE;b++)
if(array[a] > array[b])
{
temp=array[b];
array[b]=array[a];
array[a]=temp;
}
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
what does it all mean because i dont see any of it used in the actual randomizing and sorting the numbers. also, the \t isnt tabbing so it just looks like one big number, not a huge deal, but if anyone could tell me, thanks.