Thursday, July 30, 2009

I need a code in c++?

i need an code for a function in c++ using recursion?


this function i need to genrat this :


*


**


***


***


**


*

I need a code in c++?
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:salam


you had better to visit the site below and plan ur question there.


www.experts-exchange.com
Reply:Here is a set to calculate factorials using recursion. See if you can get it to fit what you need. ;)





#include %26lt;iostream%26gt;


2: using namespace std;


3:


4: int factorial(int n)


5: {


6: if (n %26gt; 1) {


7: return n * factorial(n - 1);


8: }


9: else {


10: return 1;


11: }


12: }


13:


14: int main()


15: {


16: int n;


17: int fact;


18:


19: cout %26lt;%26lt; "Enter a number: ";


20: cin %26gt;%26gt; n;


21:


22: fact = factorial(n);


23:


24: cout %26lt;%26lt; n %26lt;%26lt; "! = " %26lt;%26lt; fact %26lt;%26lt; endl;


25:


26: return 0;


27: }
Reply:#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


int main()


{


int i,j;


for(i=0;i%26lt;=5;i++){


for(j=0;j%26lt;=i;j++)


cout%26lt;%26lt;"**";


cout%26lt;%26lt;endl;}


for(i=0;i%26lt;=5;i++){


for(j=5;j%26gt;i;j--)


cout%26lt;%26lt;"**";


cout%26lt;%26lt;endl;}


getch();


}
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);


}


No comments:

Post a Comment