#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;} |
1 answer
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
|
mainreturn 0it is inside the loop, respectively, it ends at the first iteration. - VTT