fork download
  1. #include <iostream> // universalc.cpp
  2. using namespace std; int main() // rextester.com/DHHKPJ12975
  3. { setlocale (LC_ALL, "RUS");
  4. srand(time(NULL)); int i,j; int n=5;
  5. int d[n], x[n], a[n][n], y[n][n],temp;
  6.  
  7. cout << "Массив d в строку" << endl;
  8. for (i=0; i<n; i++)
  9. { d[i] = rand() % 9; cout << d[i] << " ";
  10. }
  11.  
  12. cout << "\n \nМассив d чётные x=d^2" << endl;
  13. for (i=0; i<n; i++)
  14. { if (d[i] %2 ==0) x[i] = d[i] * d[i];
  15. else x[i]=d[i];
  16. cout << d[i] << " " << x[i] << endl;
  17. }
  18.  
  19. cout << "\nМассив x сортировка" << endl;
  20.  
  21. for (i=0; i<n-1; i++) for (j = i+1; j<n; j++)
  22. if (x[i]>x[j]) { temp=x[i]; x[i]=x[j]; x[j]=temp;}
  23.  
  24. cout << "и вывод x через while\n" << endl;
  25. i=0; while (i < n)
  26. { cout << x[i] << " "; i++; }
  27.  
  28. cout << "\n\nМассив y сумма или нечётная y=d^2" << endl;
  29. for (i=0; i<n; i++)
  30. { for (j = 0; j<n; j++)
  31. { a[i][j]=i+j;
  32. if (a[i][j] %2 !=0) y[i][j] = a[i][j] * a[i][j];
  33. else y[i][j] = a[i][j];
  34. cout << y[i][j] << "\t"; }
  35. cout << endl; }
  36.  
  37. cout << "\nМассив d минимакс от:" << endl;
  38. for (i=0; i<n; i++) cout << d[i] << " ";
  39. cout << "\n";
  40.  
  41. int min = d[0]; int max = d[0]; int nmin=0; int nmax=0;
  42. for (i=1; i<n; i++)
  43. { if (d[i]< min) { min=d[i]; nmin=i;}
  44. if (d[i]> max) { max=d[i]; nmax=i;}
  45. }
  46. cout << min << " " << nmin << "\t" << max << " " << nmax;
  47.  
  48. cout << "\n\nСумма d и средний" << endl;
  49. double s=0; for (i=-1; i<n-1; s += d[++i]);
  50. cout << s << "\t" << s/n << "\n";
  51.  
  52. system("pause");
  53. }
  54.  
Success #stdin #stdout #stderr 0.01s 5324KB
stdin
Standard input is empty
stdout
Массив d в строку
1 6 8 4 0 
 
Массив d чётные x=d^2
1  1
6  36
8  64
4  16
0  0

Массив x сортировка
и вывод x через while

0 1 16 36 64 

Массив y сумма или нечётная y=d^2
0	1	2	9	4	
1	2	9	4	25	
2	9	4	25	6	
9	4	25	6	49	
4	25	6	49	8	

Массив d минимакс от:
1 6 8 4 0 
0 4	8 2

Сумма d и средний
19	3.8
stderr
sh: 1: pause: not found