Advertisement
kk258966

9/26 進階程式設計上課程式

Sep 26th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6.     int i;
  7.     int num,no[11];
  8.     int count=0;
  9.     srand(time(NULL));
  10.  
  11. //////////////////陣列歸零////////////////////////
  12.  
  13. for (i=0;i<=11;i++)
  14. no[i]=0;
  15.  
  16. /////////////////隨機產生不重複的數字/////////////
  17.  
  18. while(count<5)
  19. {
  20.               num=rand()%11;
  21.               if(no[num]==0)
  22.               {
  23.               no[num]=1;
  24.               count++;
  25.               printf("%d ",num);
  26.               }
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement