Monday, July 27, 2009

How can i make a program in c++ which has an output like a pyramid by using asterisk.?

1.What preprocessor(s) I will going to use?





The program's output goes like this:


Enter a number: 3


*


**


***


or


Enter a number: 5


*


**


***


****


*****





This program having a size or number of asterisk base on


the integer inputted.





2. Can you give me the exact code/program for that. I wish that the code you will going to give to me goes like this:





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


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


main()


{


?


?


?


?


?


?


?


getch();


return 0;


}





The question mark means the body of program that i dont know what it is supposedly.





We are using C++ language.





I hope you will answer my question exactly!





Thanks!

How can i make a program in c++ which has an output like a pyramid by using asterisk.?
The code below will work.





int main()


{


int aNum,i;


cout%26lt;%26lt;"enter a number";


cin%26gt;%26gt; aNum;


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


{


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


cout%26lt;%26lt;"*";// end of nested loop


cout%26lt;%26lt;'\n';


}// end of outer loop


return 0;


}
Reply:Someone already gave you a very nice answer for this question.
Reply:You need to do a loop in there after taking the user input for the lines (and number of stars/asterisks).





For instance, here's the 'thought process':





cout %26lt;%26lt; "How many lines do you want?" %26lt;%26lt; endl;


cin %26gt;%26gt; lines;





do {


(Put output code here!)


lines --;


} while (lines %26gt; 0);





This is just off the top of my head....for the exact code, I'd have to reference some material.


No comments:

Post a Comment