0
隨着它們的定位標記,產生一個輸入數量的隨機數字的最佳方法是什麼?像以下C - 用它們的定位標籤生成一個輸入數量的隨機數字
Pos | Val
0 | 2
1 | 924
2 | 356
目前我已經在輸入的數字量從0-1000隨機地產生,但我試圖找出如何具有從0 2 4中所列,1,...,3,定位,旁邊的相應的號碼。
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int n;
int r;
int x;
printf("Enter an integer");
scanf("%d", &n);
x = n;
for(n=0; n<x; n++) {
r = (rand()%1000) + 1;
printf("%d \n", r);
}
return 0;
}
只要改變你的'printf'語句來打印你的循環變量'N' format你的輸出,那麼也許一個標籤或其他分隔符,然後是您的'|'分隔符,然後是您現在生成的隨機值。 – hnefatl
對不起,我對如何做到這一點感到困惑,這是我的第一個程序。 –
'printf(「%d |%d \ n」,n,r);' – Koshinae