Question

#include <iostream> using namespace std; void drawRect(int h, int w) {} int main() {} Write a...

#include <iostream>
using namespace std;

void drawRect(int h, int w) {}

int main() {}

Write a program that produces h x w rectangles comprised of alternating columns of 1's and 0's (where h and w all user-specified).

For example:

 
 
 

Enter the desired dimensions for a rectangle: 6 4

 

Result:

 

1010

1010

1010

1010

1010

1010

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

void drawRect(int h, int w) {
    int n = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << n;
            n = (n+1)%2;
        }
        cout << endl;
    }
}

int main() {
    int h, w;
    cout << "Enter the desired dimensions for a rectangle: ";
    cin >> h >> w;
    drawRect(h, w);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
#include <iostream> using namespace std; void drawRect(int h, int w) {} int main() {} Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT