Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Draw a fancy pattern Write a program called xtreme.c that reads an (odd) integer n from standard input, and prints an n x n a

Draw a fancy pattern

Write a program called xtreme.c that reads an (odd) integer n from standard input, and prints an nxn a square of asterisks and dashes in the following pattern:

n: 9

*---*---* -*-----*- --*---*-- ---*-*--- *---*---* ---*-*--- --*---*-- -*-----*- *---*---*

n: 15

*---*-----*---* -*---*---*---*- --*---*-*---*-- ---*---*---*--- *---*-----*---* -*---*---*---*- --*---*-*---*-- ---*---*---*--- --*---*-*---*-- -*---*---*---*- *---*-----*---* ---*---*---*--- --*---*-*---*-- -*---*---*---*- *---*-----*---* 

n: 25

*---*---*---*---*---*---* -*---*---*-----*---*---*- --*---*---*---*---*---*-- ---*---*---*-*---*---*--- *---*---*---*---*---*---* -*---*---*-----*---*---*- --*---*---*---*---*---*-- ---*---*---*-*---*---*--- *---*---*---*---*---*---* -*---*---*-----*---*---*- --*---*---*---*---*---*-- ---*---*---*-*---*---*--- *---*---*---*---*---*---* ---*---*---*-*---*---*--- --*---*---*---*---*---*-- -*---*---*-----*---*---*- *---*---*---*---*---*---* ---*---*---*-*---*---*--- --*---*---*---*---*---*-- -*---*---*-----*---*---*- *---*---*---*---*---*---* ---*---*---*-*---*---*--- --*---*---*---*---*---*-- -*---*---*-----*---*---*- *---*---*---*---*---*---*

For more examples of this pattern, see the example program output at the end of this question

You can assume n is odd and >= 5.

Make your program match the examples below exactly.

This exercise is designed to give you practice with while loops, if statements and some mathematical operators.

As the course has not taught arrays yet, you are not permitted to use an array in this exercise.

./xtreme Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./xtreme Enter size: 7 *-----* -*---*- --*-*-- ---*--- --*-*-- -*---*- *-----* ./xtreme Enter size: 11 *---*-*---* -*---*---*- --*-----*-- ---*---*--- *---*-*---* -*---*---*- *---*-*---* ---*---*--- --*-----*-- -*---*---*- *---*-*---* ./xtreme Enter size: 13 *---*---*---* -*---*-*---*- --*---*---*-- ---*-----*--- *---*---*---* -*---*-*---*- --*---*---*-- -*---*-*---*- *---*---*---* ---*-----*--- --*---*---*-- -*---*-*---*- *---*---*---* ./xtreme Enter size: 17 *---*---*---*---* -*---*-----*---*- --*---*---*---*-- ---*---*-*---*--- *---*---*---*---* -*---*-----*---*- --*---*---*---*-- ---*---*-*---*--- *---*---*---*---* ---*---*-*---*--- --*---*---*---*-- -*---*-----*---*- *---*---*---*---* ---*---*-*---*--- --*---*---*---*-- -*---*-----*---*- *---*---*---*---* 

Assumptions/Restrictions/Hints

You may assume that you will be given only integers as input.

You may assume that all input is valid.

Hint:

With printing exercises it's helpful to think in terms of rows and columns. Try and figure out what values the asterisks show up on by drawing these X's out on paper, alongside their row and column values.

Try thinking about how you might print out the diagonal lines seperately, and then think about how you might be able to combine them.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions