fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int x[10];
  5. int main() {
  6. srand (time(NULL));
  7.  
  8. //int v1 = (rand()%11)*4-20;
  9. //cout<<v1<<endl;
  10. // your code goes here
  11.  
  12. for(int i=0;i<10;i++){
  13. x[i]=(rand()%11)*4-20;
  14. }
  15. for(int i=0;i<10;i++){
  16. cout<<x[i]<<" ";
  17. }
  18. int s=0;
  19. for(int i=0;i<10;i++){
  20. s+=x[i];
  21. }
  22.  
  23. cout<<endl<<"s="<<s<<"avg="<<s/10<<endl;
  24. int pos=0;
  25. for(int i=0;i<10;i++){
  26. if (x[i]>0) pos=pos+1;
  27. }
  28. int neg=0;
  29. for(int i=0;i<10;i++){
  30. if (x[i]<0) neg++;
  31. }
  32. cout<<"neg="<<neg<<"pos="<<pos<<endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
12 -20 20 -16 12 16 -16 -4 -4 -4 
s=-4avg=0
neg=6pos=4