srand( (unsigned)time( NULL ) );
int iRand = rand()%10;
printf(Name[iRand]);
Các bác cho em hỏi tí, em muốn viết một chương trình nhỏ nhỏ như thế này :
Mô tả :
- Chương trình sẽ tự khởi tạo ngẫu nhiên một chuỗi Name ngẫu nhiên từ một số chuỗi mặc định, từ đó sẽ làm tiếp theo 1 thuật toán nào đó. Sao em viết hoài, nó chả khởi tạo ngẫu nhiên chuỗi được ạ.
Mong các bác chỉ dùm em ! Cám ơn các bác !C Code:
#include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #include <time.h> void main () { char Name [22][13] = {"VhY-VI3fg486","P7J-T8ydwt86","t98-SYrw3w76","TDR-S1e2feP6","OD6-LVrs5eU1","Tq9-S7el9qT1" ,"rp6-ZV1m8ynN","BCw-VQvWVdB1","BfA-VKmVBaB1","BMD-VAwkEBKB","Osr-AKzO0u47","Of8-KO109vf1" ,"EML-VKdiMPO1","Ip6-VEJ6yvU1","IJT-BBYsrYX1","DUl-tqeLwlV1","ST6-DVlrmf99","erS-AKfnlp41" ,"SNQ-TTdtgjN1","grE-MIrgbnN3","ZS6-M9ofvpN3"}; char s[13]; int index = random(22); Name[index][13]; getch(); }
srand( (unsigned)time( NULL ) );
int iRand = rand()%10;
printf(Name[iRand]);
pEnGwINUS.
Mình đã code được roài. Cám ơn bạn hieubm nha. Thank you very much. ^_^
C++ Code:
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main () { char Name [22][13] = {"VhY-VI3fg486","P7J-T8ydwt86","t98-SYrw3w76","TDR-S1e2feP6","OD6-LVrs5eU1","Tq9-S7el9qT1" ,"rp6-ZV1m8ynN","BCw-VQvWVdB1","BfA-VKmVBaB1","BMD-VAwkEBKB","Osr-AKzO0u47","Of8-KO109vf1" ,"EML-VKdiMPO1","Ip6-VEJ6yvU1","IJT-BBYsrYX1","DUl-tqeLwlV1","ST6-DVlrmf99","erS-AKfnlp41" ,"SNQ-TTdtgjN1","grE-MIrgbnN3","ZS6-M9ofvpN3"}; srand(time(NULL)); int index = rand()%22; return 0; }
Y!M: doxuanthangvn
Skype: doxuanthangvnn
Email: doxuanthang@hotmail.com