Science, asked by patilnv20, 10 months ago

Write a C++ program to find the sum of Zig-Zag pattern in a given matrix. FUNCTIONAL REQUIREMENTS: int sumZigZag(int, int, int **);

Answers

Answered by noorishahmed
1

Answer:

Program to find the sum of elements in the zigzag sequence in a given matrix. /* C Program to print the sum of elements in the Zigzag sequence in a given matrix */ //Without using pointers. #include<stdio.h> #include<stdlib.h> int main() { int m, n, sum = 0, row1 = 0, col_n = 0, diag = 0.

Explanation:

please mark as brainliest answer

Answered by atmanad0001
7

Answer:

#include<iostream>  

using namespace std;  

int main()  

{  

 int r, c, i, j, sum = 0;  

 cin>>r>>c;  

 int mat[r][c];  

 for(i = 0; i < r; i++){  

   for(j = 0; j < c; j++){  

     cin>>mat[i][j];  

   }  

 }  

 for(j = 0; j < c; j++){  

    sum += mat[0][j];  

 }  

 for(i = 1; i <= r-2; i++){  

   for(j = c-2; j > 0; j--){  

     sum += mat[i][j];  

   }  

 }  

 for(j = 0; j < c; j++){  

   sum += mat[r-1][j];  

 }  

 cout<<"Sum of Zig-Zag pattern is "<<sum;  

 return 0;  

}

All test cases passed.

Similar questions