Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int n;
- printf("Enter the size of the matrix: ");
- scanf("%d", &n);
- int matrix[n][n];
- printf("Enter the elements of the matrix:\n ");
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- printf("matrix[%d][%d]: ", i, j);
- scanf("%d", &matrix[i][j]);
- }
- }
- printf("The matrix:\n");
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- printf("%d\t", matrix[i][j]);
- }
- printf("\n");
- }
- int zeroElements = 0;
- for (int i = 1; i < n; i++) {
- int diagonalSize = n - i;
- if (diagonalSize > 1) {
- for (int j = 0; j < diagonalSize; j++) {
- if(matrix[j][i + j] == 0) {
- zeroElements = zeroElements + 1;
- }
- }
- }
- }
- for (int i = 1; i < n; i++) {
- int diagonalSize = n - i;
- if (diagonalSize > 1) {
- for (int j = 0; j < diagonalSize; j++) {
- if(matrix[i + j][j] == 0) {
- zeroElements = zeroElements + 1;
- }
- }
- }
- }
- printf("Elements with zero: %d", zeroElements);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement