Jul 27, 2009 at 4:56am UTC
i have a codes like this
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
for(int a=1;a<6;a++)
{
for(int b=1;b<6;b++)
{
cout <<"*";
}
cout <<endl;
}
getch();
return 0;
}
its too complex for me to convert it to recursive form ,any idea how to convert it?
Jul 27, 2009 at 6:29am UTC
You can't like this. It needs to be in a separate function. And actually, that isn't complex at all...go read up recursive functions and you should be able to figure it out.
Jul 27, 2009 at 9:50am UTC
No need to do separation function ,i had figure it out ,here is the solution:
#include <iostream>
#include <conio.h>
using namespace std;
int b = 0;
int c = 0;
void Symbol(int a)
{
if(c>=a)
{return ;}
if(b>=a)
{
cout<<endl;
c++;
b = 0;
Symbol(a);
}
else
{
cout <<"#";
b++;
Symbol(a);
}
}
int main()
{
Symbol(5);
getch();
return 0;
}
Jul 27, 2009 at 9:58am UTC
Use [co de][/co de] tags please.
You should pass the counter values as argument in recursive function, you shouldn't have them as globals