We will draw a recursively defined picture in this program C
We will draw a recursively defined picture in this program. Create a function void fractal(int length, int spaces). This function will print out a certain number of stars * and spaces. C++
Program 3: Fractal Drawing We will draw a recursively defined picture in this program Create a function void fractal(int length, int spaces). This function will print out a certain number of stars and spaces. · If length is 1 print out the number of spaces given followed by 1 star. If the length is greater than one do the following: 1. Print the fractal pattern with half the length and the same number of spaces. 2. Print the number of spaces given followed by length stars. 3. Print the fractal pattern with half the length and spaces+(length/2) spaces in front of it. Once your function works, prompt the user for a integer x and execute fractalfx,0) You will not receive credit if your function is not recursive. Fractal Generator Enter an integer> 0: 8Solution
#include<iostream.h>
#include<conio.h>
void fractal(int,int);
void main()
{
clrscr();
int x;
cout<<\"Enter an integer> 0: \";
cin>>x;
fractal(x,0);
getch();
}
void fractal(int length, int spaces)
{
if(length == 1)
{
for(int i = 1; i <= spaces; i++)
cout<<\" \";
cout<<\"*\ \";
}
else {
fractal(length/2,spaces);
for(int i = 1; i <= spaces; i++)
cout<<\" \";
for( i = 1; i <= length; i++)
cout<<\"*\";
cout<<\"\ \";
fractal(length/2,spaces+(length/2));
}
}
