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-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 will 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 submit complete solution of the question.
A)Use " for " loops to construct a program that displays a pyramid of numbers on the screen.?
Which language do you want to use?
int resp = GetUserInput(); // Validates 0-9
for (int i = 1; i %26lt;= resp; i++)
{
for (int j = 0; j %26lt; resp - i + 2; j++)
print(' ');
for (int j = 0; j %26lt; i; j++)
{
print(i);
print(' ');
}
print('\n'); // newline
}
myspace quizzes
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment