Any help of any king would be really really appriciated (please read before you judge. I am not asking you to do my homework, i just ask help).
So I have this homework and i have been strungling a lot and I came here to get some help since deadline is in 2 days.
The main thing is to input the level of the pattern and get the following patterns using a recursive function (naming it voin drawPattern(long level, long ident); )
Level____|0___|1___|2____|3________|4________________and so on...
________|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pattern__|*___|*___|*____|*________|*
________|____|**__|**___|**_______|**
_____________| *__|_*___|_*_______|_*
_____________|____|****_|****_____|****
__________________|__*__|__*______|__*
__________________|__**_|__**_____|__**
__________________|___*_|___*_____|___*
__________________|_____|********_|********
________________________|____*____|____*
________________________|____**___|____**
________________________|_____*___|_____*
________________________|____****_|____****
________________________|______*__|______*
________________________|______**_|______**
________________________|_______*_|_______*
________________________|_________|****************
__________________________________|________*
__________________________________|________**
__________________________________|_________*
__________________________________|________****
__________________________________|__________*
__________________________________|__________**
__________________________________|___________*
__________________________________|________********
__________________________________|____________*
__________________________________|____________**
__________________________________|_____________*
__________________________________|____________****
__________________________________|______________*
__________________________________|______________**
__________________________________|_______________*
__________________________________|
(the |'s, _'s and ~'s are not included in the pattern)
I get the main idea(the stars at the middle are 2^level
and that the pattern above middle is the same as bellow but have 2^(level-1) spaces before the * and stuff)
and recursive of the pattern but i have problems creating the function. I have created a fuction to aid the printing(void printNchars(long n, char c)):
void printNchars(long n, char c)
{
long i;
for(i=0;i<n;++i)
{
printf("%c",c);
}
}
I think the ident on drawPattern should be the number of spaces. I really wouldnt ask for code if i really really didnt have the need to but I am really desperate an I need your help por favor.
Any help of any king would be really really appriciated.
32 Replies - 1017 Views - Last Post: 02 December 2012 - 10:35 PM
#1
problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 03:37 PM
Replies To: problem Draw Pattern with recursive function on C. help please
#2
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 03:58 PM
BUMP
#3
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 04:30 PM
BUMP
#4
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 04:43 PM
kk. i am bumping my head on the wall
#5
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 05:18 PM
BUMP
#6
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 05:24 PM
BUMP
#7
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 07:19 PM
BUMP
#8
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 07:52 PM
BUMP!!!
#9
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 07:53 PM
Does drawPattern have to be the recursive function?
#10
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 08:09 PM
#11
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 09:07 PM
The column is a fixed width at any level, the position of the star depends on the row.
So a function could be created for that.
So something like so :-
With the recursive function it will be useful to pass a current level and perhaps other parameters.
I'll have a look at that.
So a function could be created for that.
So something like so :-
void print_column(int level, int row);
With the recursive function it will be useful to pass a current level and perhaps other parameters.
I'll have a look at that.
#12
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 10:00 PM
If a parameter is used for the current level, several levels can be drawn.
With another (variable) parameter columns can be added.
Within each level there are a number of rows so another parameter could be used for that.
// current starts at 0
void drawPattern1(long current, long level)
{
if(current <= level) {
cout << " level " << current << endl;
drawPattern1(current+1, level);
}
}
With another (variable) parameter columns can be added.
// col initially starts at 0
void drawPattern2(long current, long col, long level)
{
if(current > level)
return;
if(col <= level)
{
cout << " col " << col;
drawPattern2(current, col+1, level);
}
else
{
cout << " level " << current << endl;
drawPattern2(current+1, 0, level);
}
}
Within each level there are a number of rows so another parameter could be used for that.
#13
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 10:09 PM
With 7/9 of the OPs posts being BUMPS I think you're being too kind #define.
#14
Re: problem Draw Pattern with recursive function on C. help please
Posted 30 November 2012 - 11:18 PM
It's a tricky pattern, but it looks like there should be an easier answer.
Anyway I answered, that stopped them bumping for now.
Anyway I answered, that stopped them bumping for now.
#15
Re: problem Draw Pattern with recursive function on C. help please
Posted 01 December 2012 - 08:12 AM
CTphpnwb, on 30 November 2012 - 10:09 PM, said:
With 7/9 of the OPs posts being BUMPS I think you're being too kind #define.
I am sorry...
Thanks #define, I think i can start trying things again.
I am still a beginer with C and recursive functions (first time did recursive functions was 1 week before
and that example was quite simple). Is there a way to set a parameter that starts from a number and counts
down or up without making it an input? Cause i tried some ways within the recursive function but i can stop
it going back to the initial price it was set every time the the recursion runs.
|
|

New Topic/Question
Reply




MultiQuote





|