Question

Nested loops

1. Request an odd integer value between 10 and 20. Input should be validated until correct. Use a nested loop to output the b

c++ nested loops

0 0
Add a comment Improve this question Transcribed image text
Answer #1

******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As per Chegg expert answering guidelines, Experts are supposed to answer only a certain number of questions/sub-parts in a post. Please raise the remaining as a new question as per Chegg guidelines.
******************************************************************************************

#include <iostream>

using namespace std;

int main() {

int n ;

do{

cout<<"Enter an odd integer between 10 and 20: ";

cin>>n;

}while((n>20)&&(n<10));

char a[n][n];

for(int i=0;i<n;i++)

{

for(int j=0;j<n;j++)

{

if((i==0)||(j==0)||(i==(n-1))||(j==(n-1)))a[i][j]='X';

else if(i==j)

{

a[i][j]='X';

}

else if ((i+j)==(n-1))

{

a[i][j]='X';

}

else

{

a[i][j]='-';

}

}

}

for(int i=0;i<n;i++)

{

for(int j=0;j<n;j++)

{

cout<<a[i][j]<<" ";

}

cout<<endl;

}

  return 0;

}

C++14 14 Shortcuts S Reset Copy for(int j=0; j<n; j++) if((i==0)||(j==0)||(i==(n-1))||(j==(n-1)))a[i]: else if(i==j) 15 - a[i

Add a comment
Know the answer?
Add Answer to:
Nested loops c++ nested loops 1. Request an odd integer value between 10 and 20. Input...
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