Home > Software engineering >  Digital pyramid
Digital pyramid

Time:11-08


How to write like that? thank you

CodePudding user response:

Print 9
Print 888
.

A total of 9 lines, written in loop directly, can cycle 9 times, circle from 9 to 1
Set the line number of I, you will need to print the number (10 - I), 2 * I - 1,
Since each loop to print multiple Numbers, in the inner loop can also be used to write, cycle number is 2 * I - 1
For I=9 to 1 step 1 (outer loop, a loop to print a line)
Another needs to calculate the starting position (assuming the triangle on the left side of the starting position of the distance distance is 10 characters), the bank's starting position I 10 + total number of rows from the left margin -i (is 9 in the subject line, so the first I line starting position from the left 19 - I)
The print TAB (19 - I);
For j=1 to 2 * I - 1 (the inner circle, a loop to print a number)
Print the I;

Lining, of course, also can need not circulation, directly use string functions to output the continuous 2 * I - a digital,

CodePudding user response:

reference 1/X - I - n reply:
print 9
Print 888
.

A total of 9 lines, written in loop directly, can cycle 9 times, circle from 9 to 1
Set the line number of I, you will need to print the number (10 - I), 2 * I - 1,
Since each loop to print multiple Numbers, in the inner loop can also be used to write, cycle number is 2 * I - 1
For I=9 to 1 step 1 (outer loop, a loop to print a line)
Another needs to calculate the starting position (assuming the triangle on the left side of the starting position of the distance distance is 10 characters), the bank's starting position I 10 + total number of rows from the left margin -i (is 9 in the subject line, so the first I line starting position from the left 19 - I)
The print TAB (19 - I);
For j=1 to 2 * I - 1 (the inner circle, a loop to print a number)
Print the I;

Lining, of course, also can need not circulation, directly use string functions to output the continuous 2 * I - a digital,

Can write code? Thank you for the

CodePudding user response:

refer to the second floor a879501017 response:
Quote: refer to 1st floor X - I - n reply:

Print 9
Print 888
.

A total of 9 lines, written in loop directly, can cycle 9 times, circle from 9 to 1
Set the line number of I, you will need to print the number (10 - I), 2 * I - 1,
Since each loop to print multiple Numbers, in the inner loop can also be used to write, cycle number is 2 * I - 1
For I=9 to 1 step 1 (outer loop, a loop to print a line)
Another needs to calculate the starting position (assuming the triangle on the left side of the starting position of the distance distance is 10 characters), the bank's starting position I 10 + total number of rows from the left margin -i (is 9 in the subject line, so the first I line starting position from the left 19 - I)
The print TAB (19 - I);
For j=1 to 2 * I - 1 (the inner circle, a loop to print a number)
Print the I;

Lining, of course, also can need not circulation, directly use string functions to output the continuous 2 * I - a digital,

Can write code? Thank you

Ha ha

CodePudding user response:





Give you a concise code, you want to knock,
If you are the teacher corrects students' papers carefully, this code should be in the interest of your teacher, you have to consider how to explain the principle of this code to your teacher, to indicate that this is you make it yourself,

CodePudding user response:

Very clever way upstairs,


But I think the circulation in the body that is changed to the better:
 Me. Print Space $(20 - I) & amp; String $(I + I - 1, 58 - I) 

CodePudding user response:

refer to fifth floor a toast to invite the bright moon response:
way upstairs quite clever,


But I think the circulation in the body that is changed to the better:
 Me. Print Space $(20 - I) & amp; The String $(I + I - 1, 58 - I) 


To come, to see to still have a shorter,
Why don't challenge za FQ try out 280 words?
https://xw.qq.com/cmsid/20200326A0BRT300

CodePudding user response:

refer to fifth floor a toast to invite the bright moon response:
way upstairs quite clever,


But I think the circulation in the body that is changed to the better:
 Me. Print Space $(20 - I) & amp; The String $(I + I - 1, 58 - I) 


Don't string, using numerical solution

CodePudding user response:

My main consideration is not code length, but the operation efficiency,

CodePudding user response:

11 references, a toast to invite the bright moon response:
my main consideration is not the problem of code length, but the operation efficiency,

So I gave it to a longer numerical code instead of string concatenation scheme,

CodePudding user response:

Directly define a long string, use, spell well,
And then directly into the array, print circulation,
 
Dim (s) as string, I as long
Const STR as string="9, 888, 77777,,,,,"
S=split (STR, ", ")
For I=0 to 8
Print STR (I)
Next

CodePudding user response:

Dim aa, I, j
Aa=""
For I=9 To 1 Step - 1
For j=1 To 20
If j & lt;=I Or j & gt;=20 - Then I
Aa=aa & amp; "
"The Else
Aa=aa & amp; I
End the If
Next
Aa=aa & amp; VbCrLf
Next
Print aa
  • Related