Advertisement
fahimkamal63

C++ 2-D array

Apr 19th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int t; cin >> t;
  6.     while(t--){
  7.         int n; cin >> n;
  8.         int a[n][n], i, j;
  9.         //  Taking Input
  10.         for(i = 0; i < n; i++){
  11.             for(j = 0; j < n; j++){
  12.                 cin >> a[i][j];
  13.             }
  14.         }
  15.         int row[n] = {1}, col[n] = {1};
  16.         for(i = 0; i < n; i++){
  17.             row[i] = 1;
  18.             col[i] = 1;
  19.         }
  20.         for(i = 0; i < n; i++){
  21.             for(j = 0; j < n; j++){
  22.                 if(a[i][j] == 0){
  23.                     row[i] = 0;
  24.                     col[j] = 0;
  25.                 }
  26.             }
  27.         }
  28.  
  29.         for(i = 0; i < n; i++){
  30.             for(j = 0; j < n; j++){
  31.                 if(row[i] == 0 || col[j] == 0){
  32.                     a[i][j] = 0;
  33.                 }
  34.             }
  35.         }
  36.  
  37.         //  Showing result
  38.         for(i = 0; i < n; i++){
  39.             for(j = 0; j < n; j++){
  40.                 cout << a[i][j] << ' ';
  41.             }
  42.         }
  43.         cout << endl;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement