HELP PLEASE, I have a problem fi (aij) - the product of the elements in each column under the main diagonal of the matrix. F (fi (aij)) is the arithmetic average of fi (aij) . Where is my mistake?

 #include <stdio.h> #include <stdlib.h> #define n 5 void sort(int a[n][n]); void dob (int d[n-1],int a[n][n]) { int i,j; d=1; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if (i>j) { d=d+a[i][j]; printf("%d", d); } } } { double ser,s; for(i=0;i<n-1;i++) s=0; for(i=0;i<n-1;i++) s=s+d[i]; ser=s/(n-1); printf("\n Seredne aryfmetychne=%lf",ser); } } void main(void) { int i,j,k; int a[n][n]; int d[i]; system("cls"); for (i=0; i<n; i++) { for (j=0; j<n; j++) { printf("a[%d][%d] = ", i+1, j+1); scanf("%d", & a[i][j]); } } system("cls"); printf("Old array :\n"); for (i=0; i<n; i++) { for (j=0; j<n; j++) printf("%5d", a[i][j]); printf("\n"); } sort(a); printf("New array :\n"); for (i=0; i<n; i++) { for (j=0; j<n; j++) { printf("%5d", a[i][j]); } printf("\n"); } printf("\n"); dob(d,a); } void sort(int a[n][n]) { int i, k, j, c; for(i = 0; i < n; i++) { for(k = n-1; k>=0; k--) { for(j = 0; j < k; j++) { if(a[i][j] < a[i][j+1]) { c = a[i][j]; a[i][j] = a[i][j+1]; a[i][j+1] =c; } } } } } 

Closed due to the fact that off-topic participants rdorn , user194374, aleksandr barakin , Alex , Denis Bubnov 6 Dec '16 at 8:40 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - rdorn, Community Spirit, Alex, Denis Bubnov
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Where is your mistake? Not compiled, or the result is not the same? Dobutok - what's this? - 0xdb
  • dobutok - a work ,,,, I can not figure out what is wrong .... the program sorts the matrix but does not count - Terry Link
  • But does the program produce something or does it count only in the mind? - 0xdb

1 answer 1

First, according to the C standard, the main function without parameters must be declared as

 int main( void ) 

You have not initialized the variable i at the beginning of the program, and therefore the following array declaration is not correct

  int i,j,k; int a[n][n]; int d[i]; ^^^^^^^^ 

Why don't you define it as

  int d[n-1]; 

It is even better to define it as having the type long long int , because the product of integers may not fit in an int object.

  long long int d[n-1]; 

the function itself of the product of elements in the columns under the main diagonal may look as follows

 void dob ( const int a[n][n], long long int d[n-1] ) { size_t k = 0; for ( size_t col = 0; col < n; col++ ) { if ( col + 1 < n ) { long long int result = 1; for ( size_t row = col + 1; row < n; row++ ) { result *= a[row][col]; } d[k++] = result; } } } 

Accordingly, the function call will be as follows

 dob( a, d ); 

Any output to the console of the results of the function should be taken out of the function and placed in main ,