PLEASE ANSWERED IN C++ AND WRITE ALL STEP.
Use" for" loops to construct a program that displays a pyramid of numbers on the screen.?
Hints
You may nest two inner loops, one to print spaces and one to print numbers (0-9), inside an outer loop that steps down the screen from line to line.
ask user to enter any number from 0 to 9. if he enter 3 out put will be.
*****1
****2 2
***3 3 3
**4 4 4 4
In the above sample there will no'*' in real and it is not appear in screan . it will write only for submitting sample.if I do not write * prew of sample is not correct in appearence.
PLEASE GIVE COMPLETE SOLUTION. THANKS
Use "for" loops to construct a program that displays a pyramid of numbers on the screen.?
cout %26lt;%26lt; "How tall is your pyramid?" %26lt;%26lt; endl;
int height
cin %26gt;%26gt; height;
//main loop, one iteration of this will create each level
for(int i = 1; i %26lt;= height; i++)
{
//print the '*'s
for(int j = i; j %26lt;= height; j++)
{
cout %26lt;%26lt; "asterisk";
}
//print the numbers
for(int j = 0; j %26lt; =i; j++)
{
cout %26lt;%26lt; i %26lt;%26lt; " ";
}
poems
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment