Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX_SIZE 100
- int main() {
- int size, i, j;
- printf("Enter the size of the matrix: ");
- scanf("%d", &size);
- int matrix[size][size];
- // Input the elements of the matrix
- printf("Enter the elements of the matrix:\n");
- for (i = 0; i < size; i++) {
- for (j = 0; j < size; j++) {
- printf("Enter element [%d][%d]: ", i, j);
- scanf("%d", &matrix[i][j]);
- }
- }
- // Displaying the matrix
- printf("Matrix info:\n");
- for (i = 0; i < size; i++) {
- for (j = 0; j < size; j++) {
- printf("%d ", matrix[i][j]);
- }
- printf("\n");
- }
- int diagonalsWithZero = 0;
- // Getting diagonals above the secondary diagonal
- for (i = 0; i < size - 1; i++) {
- int diagonal_length = size - i - 1;
- if (diagonal_length > 1) {
- for (j = 0; j < diagonal_length; j++) {
- if(matrix[j][size - i - 2 - j] == 0) {
- diagonalsWithZero++;
- break;
- }
- }
- }
- }
- // Getting diagonals below the secondary diagonal
- for (i = 1; i < size; i++) {
- int diagonal_length = size - i;
- if (diagonal_length > 1) {
- for (j = 0; j < diagonal_length; j++) {
- if(matrix[i + j][size - 1 - j] == 0) {
- diagonalsWithZero++;
- break;
- }
- }
- }
- }
- printf("Diagonals with zeros as value: %d", diagonalsWithZero);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement