12,403,812 members (72,679 online)
Rate this:
See more:
How i can get the following pattern using c or C++

```*     *
**   **
* * * *
*  *  *
* * * *
**   **
*     *
```

here the user input is the no of rows and there should be diagonals from both ends. Please help me.
Posted 25-Jun-13 2:24am
Updated 25-Jun-13 2:50am
Nelek96.6K
v6
ThePhantomUpvoter 25-Jun-13 8:45am

And what have you tried so far to accomplish your homework? What code have you written? What problems have you encountered? Did you ask your teacher? Have you reviewed your class notes?

i have tried but. I am not able to get such a pattern . please help me
ThePhantomUpvoter 25-Jun-13 8:55am

Help you with what exactly? I do not see any evidence at all that you have tried to do anything yourself to do your homework before asking someone to do it for you. It's your homework, don't you think that you should at least try to do it? I am not going to get any benefit from doing your homework for you.
CPallini 25-Jun-13 8:50am

Wow, I see a pattern, there.
H.Brydon 26-Jun-13 12:37pm

Virtual +5 for that one. Yes. :-)

Rate this:

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

Having said that, it's not complex - but I'll give you no code!

1) Allocate a character array big enough to hold the whole line (including a terminating null)
2) Set up a loop for the number of rows, (a `for` loop is fine, with a variable of curRow)
3) In the loop, clear the line to all spaces.
4) Then, set the first and last character to a '*'
5) Then, set the character at the current row number to a '*', and the character at the number of rows - (the current row + 1) to a '*'
6) Set the character at the number of rows to a null '\0'
7) Write the line
8 Repeat the loop for the next row.

Easy! Total: about 7 lines of code!

Top Experts
Last 24hrsThis month
 OriginalGriff 353 Richard MacCutchan 217 Karthik Bangalore 210 Suvendu Shekhar Giri 185 ppolymorphe 110
 OriginalGriff 7,386 Karthik Bangalore 3,127 ppolymorphe 3,100 Richard MacCutchan 2,342 F-ES Sitecore 2,262

Web02 | 2.8.160721.1 | Last Updated 25 Jun 2013