Advertisement
kk258966

5/14 C++練習一

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