I have a little problem creating random numbers in 2 arrays. First array create random numbers fine, but the other one create always same numbers, although it sometimes change them for eg. 10 10 10 10 10 10 etc... but when I run program again it says 7 7 7 7 7 etc..
Here is program:
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
main()
{
srand ( time(NULL) );
int i,j,switchh,switching;
int howmany = 10;
int a[howmany],b[howmany];
for (i=0;i<howmany;i++) {
b[i] = rand() % 10+1;
}
while(1) {
switchh=0;
for (i=0; i<howmany-1;i++) {
if (b[i]>b[i+1]) {
int switching=b[i];
b[i]=b[i+1];
b[i+1]=switching;
switchh = 1;
}
}
if(switchh==0) {
break;
}
}
srand ( time(NULL) );
for (j=0;j<howmany;j++) {
a[j] = rand() % 10+1;
}
while(1) {
switchh=0;
for (j=0; j<howmany-1;j++) {
if (a[j]>a[j+1]) {
int switching=a[j];
a[j]=a[j+1];
a[j+1]=switching;
switchh = 1;
}
}
if(switchh==0) {
break;
}
}
for (j=0;j<howmany;j++) {
printf("%d\n",a[i]);
}
for (i=0;i<howmany;i++) {
printf("%d\n",b[i]);
}
return 0;
}