hi,
i'm trying to fill an array with random numbers and then sort them via bubblesort. it seems to work so far. the problem is, that i seem to get the same numbers for the same input. somehow the randomness isn't working. anyone an idea why?
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c, d, e, f;
printf("number of elements from 1 to x:\n");
scanf("%d", &b);
printf("max random number:\n");
scanf("%d", &f);
int array[b];
for(a=0; a<b; a++)
{
c = rand() %f+1;
array[a] = c;
}
for(a=0; a<b; a++)
{
for(d=0; d<b-1; d++)
{
if(array[d] > array[d+1])
{
e=array[d];
array[d]=array[d+1];
array[d+1]=e;
}
}
}
for(a=0; a<b; a++)
{
printf("%d\n", array[a]);
}
return 0;
}
greetings,
grindbert