Board logo

標題: 亂數 - 產生介於指定範圍內的隨機亂數 (一) [打印本頁]

作者: tonyh    時間: 2013-8-17 14:48     標題: 亂數 - 產生介於指定範圍內的隨機亂數 (一)

本帖最後由 tonyh 於 2013-8-17 14:54 編輯

產生20個介於1~3的隨機亂數
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     for(int i=1; i<=20; i++)
  8.     {
  9.         cout<<rand()%3+1<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 張瀚仁    時間: 2013-8-17 14:55

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     for(int i>=1;i<=20;i++)
  8.     {
  9.          cout<<rand()%3+1<<endl;                  
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 鎧言    時間: 2013-8-17 14:55

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     for(int i=1; i<=20; i++)
  8.     {
  9.         cout<<rand()%3+1<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 郭凡瑛    時間: 2013-8-17 14:55

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=1; i<=20; i++)
  7.     {
  8.         cout<<rand()%3+1<<endl;  
  9.     }
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

作者: 蘇昱安    時間: 2013-8-17 14:55

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=1; i<=20; i++)
  7.     {
  8.         cout<<rand()%3+1<<endl;  
  9.     }
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

作者: 劉泳鱔    時間: 2013-8-17 14:56

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL)
  7.     for(int i=1; i<=20; i++)
  8.     {
  9.     cout<<rand()%3+1<<endl;        
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 長逸    時間: 2013-8-17 15:00

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL);
  7.     for(int i=1; i<=20; i++)
  8.     {
  9.         cout<<rand()%3+1<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 黃柏維    時間: 2013-8-21 20:25

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. srand(time(NULL));
  7. for(int i=1;i<=20;i++)
  8.     {
  9.     cout<<rand()%3+1<<endl;      
  10.     }   
  11. system("pause");   
  12. return 0;   
  13. }
複製代碼

作者: 許逸群    時間: 2013-8-24 09:07

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     for(int i=1; i<=20; i++)
  8.     {
  9.         cout<<rand()%3+1<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2