ahmed0saber

Print 2D matrix in C++

Nov 4th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a , b , c=0 , i=0 , j;
  6.     cout << "Enter length and width of the matrix" << endl;
  7.     cout << "Length = ";
  8.     cin >> a ;
  9.     cout << "Width = ";
  10.     cin >> b ;
  11.     while (i<a)
  12.     {
  13.         i=i+1;
  14.         j=0;
  15.         cout << endl ;
  16.         while (j<b)
  17.         {
  18.             j=j+1;
  19.             c=c+1;
  20.             if (c%2==1)
  21.             {
  22.                 cout << " 0 ";
  23.             }
  24.             else
  25.             {
  26.                 cout << " 1 ";
  27.             }
  28.         }
  29.     }
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment