fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(){
  6. const int n = 6, m = 8;
  7. int array[n][m];
  8. int i, j, a1, x, z, row = 0, y;
  9. float distance = 0;
  10. float columnDistance;
  11. float minDistance = 0;
  12. cout << "Massiv" << endl;
  13. for ( i = 0; i < n; i++){
  14. columnDistance = 0;
  15. cout << endl;
  16. for ( j = 0; j < m; j++){
  17. array[i][j] = log(i + j + 1);
  18. cout << array[i][j];
  19. }
  20. }
  21. for ( x = 0; x < m; x++){
  22. columnDistance = 0;
  23.  
  24. for (z = 0; z < n; z++){
  25. //cout << array[z][x];
  26. if ( z == 0){
  27. a1 = array[z][x];
  28. }
  29. if ( z != 0){
  30. distance = abs(array[z][x]) + abs(a1);
  31. }
  32. columnDistance += distance;
  33. if (minDistance == 0){
  34. minDistance = columnDistance;
  35. }else {
  36. if (minDistance < columnDistance){
  37. continue;
  38. }else {
  39. minDistance = columnDistance;
  40. row = x - 1;
  41. }
  42. }
  43. }
  44. }
  45. cout << endl;
  46. cout << "Vector: " << endl;
  47. for (y = 0; y < n; y++){
  48. cout << array[row][y];
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0s 4196KB
stdin
Standard input is empty
stdout
Massiv

00111112
01111122
11111222
11112222
11122222
11222222
Vector: 
011111