Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Patterns GimmeCode Homework , +
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 3:24am
Edited 25-Jun-13 3:50am
Nelek59.6K
v6
Comments
ThePhantomUpvoter at 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?
Rinshad Hameed at 25-Jun-13 8:48am
   
i have tried but. I am not able to get such a pattern . please help me
ThePhantomUpvoter at 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 at 25-Jun-13 8:50am
   
Wow, I see a pattern, there.
H.Brydon at 26-Jun-13 12:37pm
   
Virtual +5 for that one. Yes. :-)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

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!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 25 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100