fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #include <time.h>
  6. #include<stdlib.h>
  7.  
  8. #include <math.h>
  9. int main()
  10.  
  11. {
  12.  
  13. int a[30];
  14.  
  15. int x;
  16.  
  17. int z=0;
  18.  
  19. srand((unsigned)time(NULL));
  20.  
  21. cout<<"原数组:";
  22.  
  23. for(int i=0;i<30;i++)
  24.  
  25. {
  26.  
  27. a[i]=rand()%21;
  28.  
  29. cout<<a[i]<<" ";
  30.  
  31. }
  32.  
  33. cout<<endl;
  34.  
  35. cout<<"输入m值<0~20>:";
  36.  
  37. cin>>x;
  38.  
  39. cout<<x<<endl;
  40.  
  41. if(x<0||x>20)
  42.  
  43. cout<<"输入数据越界!"<<endl;
  44.  
  45. else
  46. {
  47. for(int i=0;i<30;i++)
  48. {
  49. if(a[i]=x)
  50. z=z+1;
  51. }
  52.  
  53. cout<<x<<"在数组中,出现了"<<z<<"次";
  54. }
  55. return 0;
  56.  
  57. }
Success #stdin #stdout 0.01s 5304KB
stdin
18
stdout
原数组:20 12 15 11 7 14 8 16 10 7 0 0 7 4 18 10 18 11 2 20 0 5 20 20 5 12 8 1 4 0 
输入m值<0~20>:18
18在数组中,出现了30次