Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m struggling with this problem that is supposed to print a series of asterisk

ID: 3559558 • Letter: I

Question

I'm struggling with this problem that is supposed to print a series of asterisks in a diamond shape. The user is asked to input an odd integer n which then prints a diamond that has n asterisks as it's center line.

an example would be

I already wrote a program that prints a diamond, put it prints it

based on the number of rows, not the width.

the prompt used to say "Enter Number of rows". All I've done is change the prompt to the above. How can I modify this code so that the prompt only accepts an odd integer and prints the diamond based on the width and not the number of rows from the center?

If the code above is too far off from your answer to be "modified", then please help me with the problem alone above. Thanks for the help!

Explanation / Answer

using namespace std;

void main()

{

int i=0, j=0, NUM=3;

for(i=-NUM; i<=NUM; i++)

{

for(j=-NUM; j<=NUM; j++)

{

if( abs(i)+abs(j)<=NUM) // Change this condition

{ printf("*"); }

else { printf(" ");}

}

printf("/n");

}

}

The above code will prints-

*
***
*****
*******
*****
***
*

using namespace std;

void main()

{

int i=0, j=0, NUM=3;

for(i=-NUM; i<=NUM; i++)

{

for(j=-NUM; j<=NUM; j++)

{

if( abs(i)+abs(j)<=NUM) // Change this condition

{ printf("*"); }

else { printf(" ");}

}

printf("/n");

}

}