i just got an exercise i am asked to do and i have no idea what to do.
I am asked to use recursive to print a pattern without using loop:
*
**
***
****
****
***
**
*

And also :
****
***
**
*
**
***
****

Any help is very much appreciated.

Recommended Answers

All 3 Replies

i just got an exercise i am asked to do and i have no idea what to do.
I am asked to use recursive to print a pattern without using loop:
*
**
***
****
****
***
**
*

And also :
****
***
**
*
**
***
****

Any help is very much appreciated.

Do you know what recursion is? I mean can you write a recursive function? Your program's solution depends on that.You will write a recursive function print and play with its parameters.

#include<stdio.h>
#include<conio.h>
void put(int n)
{
if(n>0)
{
put(n-1);
printf("*");
}
}
void disp1(int n)
{if(n>0)
{
disp1(n-1);
put(n);
}
printf("\n");
}
void disp2(int n)
{
if(n>0)
{

put(n);
printf("\n");
disp2(n-1);

}
}

void star(int n)
{
disp1(n);
disp2(n);
}
void main()
{
int xy=4;
clrscr();
star(xy);
getch();
}

wad about this?
*
* *
* * *
* * * *
* * * *
* * *
* *
*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.