this function i need to genrat this :
*
**
***
***
**
*
I need an code for a function in c++ using recursion?
I won't write the C++ version, but I think can provide a pseudo code version. Sorry, I can't test the code, you'll need to play with it.
main()
{
printLines(3);
}
void printLines(int x)
{
if (x %26gt;= 1)
{
printLines(x-1);
printStars(x);
printLines(x-1);
}
}
void printStars(int x)
{
if (x == 1)
{
printf("*\n");
}
else
{
printf("*");
printStars(x-1);
}
}
Reply:Void PrintStars(Int Row)
{
Cout %26lt;%26lt;"\n";
For(i=0; i%26lt;Row; i++)
Count %26lt;%26lt;"*";
if Row %26lt; 3 then
PrintStars(++Row);
Cout %26lt;%26lt;"\n";
For(i=0; i%26lt;Row; i++)
Count %26lt;%26lt;"*";
}
Reply:function print(int row = 0){
if(row %26lt; 3)
for(int i=0;i%26lt;=row;i++) {
cout %26lt;%26lt; "*";
}
else
for(int i=5;i%26gt;=row;i--) {
cout %26lt;%26lt; "*";
}
if(row == 5)
return;
print(++row);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment