c語言生成1~100隨機數(shù) C語言中如何隨機輸出一個字母?
C語言中如何隨機輸出一個字母?#包括和限制。H>#包括<stdlib。H>#包含時間(&L)。H>void main(){tint I/TCHAR C/tsrand((unsigned
C語言中如何隨機輸出一個字母?
#包括和限制。H>#包括<stdlib。H>#包含時間(&L)。H>void main(){tint I/TCHAR C/tsrand((unsigned)time(null))Ti=rand()&1//I用于控制生成的字母是大寫還是小寫(TIF(I==0)T/C=“a”rand()&telse/T/TC=“a”rand()&&tprintf(%Cn”,C)}
用數(shù)字組合隨機數(shù),一個數(shù)組表示記錄的隨機數(shù),例如random 0-8生成一個隨機的8位組,數(shù)組中的每一項都不重復;例如:intrarray[8]intraryindex[8]={0,0,0,0,0}intk=0srand(100)while(K<8){intq=rand()%8 If(array index[Q-1]index[Q-1[Q-1]==1){continue}array[K]=index[Q-1]=1K}擴展數(shù)據(jù)C語言隨機輸出1~20隨機輸出1~20隨機數(shù)的1~20隨機輸出1~20個不重復1~20隨機數(shù)的隨機數(shù)[q-q-1[q-1[q-1[q-1-1]index[q-index[q-1[q-1]index[q-1[q-1]index[q-1]index[q-1]index[q-1[q-1]index[q-1[q-1]index[q-1[q-1]==a[J]){I--}對于(I=0I<20i)){printf(“=n”,a[I])}}