different random numbers generator

我要成为(c语言)高手發表於2024-04-08

include <stdio.h>

include <stdlib.h>

include <time.h>

int main(int argc, const char * argv[]){
srand((unsigned int)time(0));
int x;
printf("enter the number of numbers:");
scanf("%d",&x);
int a[x];
for (int i=0; i<x; i++) {
a[i]=rand();
for (int j=0; j<i; j++) {
if (a[j]==a[i]) {
i--;
break;
}
}
}
for (int i=0; i<x; i++) {
printf("%d ",a[i]);
}
return 0;
}

相關文章