Count null diagonals in a matrix -
i'm trying create program counts number of null diagonals in square matrix, can't seem find correct way of making index run correctly through matrix. here's incorrect code i've got far:
# include<stdio.h> # define max 100 int diagonnull (int n, int a[max][max]) { int i, j, count, null; banda = 0; for(i = n - 1; >= 0; i--){ count = 0; for(j = 0; j <= n && j < - 1; j++){ if (a[i][j] == 0) count++; } if (count == n - i) /* n - = number of elements in diagonal */ null++; else = - 1; } return null; } int main () { int n, a[max][max], i, j, null; printf ("enter value of n create square matrix of order n: "); scanf ("%d", &n); printf ("enter elements of matrix a: "); (i = 0; < n; i++){ (j = 0; j < n; j++){ scanf("%d", &a[i][j]); } } null = diagonnull (n, a); printf ("matrix has null %d diagonals", null); return 0; }
Comments
Post a Comment