#include <iostream> #include <iomanip> using namespace std; template <typename X> void enterArray(X**a,int n) {cout<<"Vvedite massiv"<<n<<"*"<<n<<endl; for (int i=0; i<n; i++) for (int j=0; j<n; j++) cin>> a[i][j];} template <typename X> void print(X**a,int n) { for (int i=0; i<n; i++, cout<<endl) for (int j=0; j<n; j++) cout<<setw(6)<<a[i][j]<< " "; } int main() {int n; cin>>n; int s=0; int ** a = new int * [n]; for (int i=0; i<n; i++) a[i]=new int [n]; enterArray(a,n); print(a,n);} {for(int i=0;i<n;i++) { for(int j=n-1;j>0;j--) { if(a[i][j]!=0) { s+=a[i][j]; n++;} } cout<<"Sred. arif="<<s/n;} return 0;} 
  • Do you know what you wrote wrong or what? .. The question is what? - AR Hovsepyan
  • I do not understand why my program only displays the array and that's it. counting does not happen - Rubusidaeus11072011
  • The brackets must be carefully arranged, in main return 0 it is inside the loop, respectively, it ends at the first iteration. - VTT
  • This corrected) displays the array now and then requests the number. - Rubusidaeus11072011
  • because in the rest of the program you are waiting for input for the secondary array initialization. - AR Hovsepyan

1 answer 1

after calling the function print(a,n) ; ie, after the output of the resulting array, you need to go to the solution of the main part of the problem, namely, calculate the arithmetic average located above the secondary diagonal.

 int k = 0; for(int i = 0; i < n - 1; ++i) for(int j = n - i - 2; j >= 0; --j) if (a[i][j]) { ++k; // считаем количество ненулевых элементов s += a[i][j]; // их сумма } cout << (double)s / k; // среднее арефметическое 
  • Everything, now figured out) Thank you so much) - Rubusidaeus11072011