Question: Hi I need some help with this question. So far I nailed the bottom part and was wondering if the same can be done with

Hi I need some help with this question. So far I nailed the bottom part and was wondering if the same can be done with the top part of 5. I have asked before but got an added int x = 5; when I am not looking for that but rather approaching this with out the need for adding an int.

1.Write a nested loop to print the following for any n x n image of odd dimensions:

Example Output (n==5):

0 0 X 0 0

0 0 0 0 0

X 0 0 0 X

0 0 0 0 0

0 0 X 0 0

Example Output (n==3):

0 X 0

X 0 X

0 X 0

The code I have so far

#include

using namespace std;

int main()

{

cout << endl;

cout << "Example output for 5" << endl; // this part I need help in or a clarity on what I should be doing.

for(int r=1; r<=5; ++r){

for(int c=1; c<=5; ++c){

if(r%2!=1 || c%2==1 || r==c )

cout << "o";

else

cout << "x";

}

cout << endl;

}

cout << endl;

cout << "Example output for 3" << endl; // this I nailed

for(int r=1; r<=3; r++){

for(int c=1; c<=3; c++){

if(r%2!=0 && c%2!=0 || r==c)

cout << "o";

else

cout << "x";

}

cout << endl;

}

cout << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!