srand(time(NULL));
for(i = 0; i < n; i++){
for(j = 0; j < (n-1); j++){
a[i][j] = rand();
}
}
我嘗試生成隨機數字,但它們是一樣的... 我該怎麼辦?C中的隨機數字
數組聲明:
int** a;
int i;
printf("Enter array size: ");
scanf("%d", &n);
a = (int**)calloc(n, sizeof(int));
for(i = 0; i < n; i++)
a[i] = (int*)calloc(n-1, sizeof(int));
你的第一個'calloc'調用應該是'的sizeof(INT *)'但你似乎可正常工作的主機,其中簡單的指針和整數具有相同的尺寸(這是大多數系統架構中的真)上。 – mpez0 2010-03-16 00:33:24