-
Good question, write with a for loop and judgment statement.
private sub command1_click()dim tuzi as integer
dim ji as integer
for tuzi = 1 to 40
for ji = 1 to 80
if tuzi * 4 + ji * 2 = 160 and tuzi + ji = 50 then
If the total number of legs of the rabbit and chicken is 160, and the rabbit and chicken are 50, the result msgbox ("The number of rabbits and chickens is as follows:" & tuzi & "、" & ji)
end if
next next
end sub
Hehe, I think of for and if when I want to solve any problem recently, I can't be saved! Also, rabbits are four-legged, right?
-
1) Let the chicken x and the rabbit y, then the system of equations can be listed according to the meaning of the question:
x+y=50
2x+4y=160, the solution is x=30, y=202)dim m as integer, n as integerm=50n=160
print "Chickens are shared";2*m-n/2;"Only,";
print "There are rabbits in total";n/2-m;"Only,"
-
Comrade upstairs! Your system of binary equations is reversed, and the system of equations is correct but x 20, y 30 hee-hee.
-
Bright statement dim ah (3,-2 same as 2,5).
Equivalent to dim (0...)3 ,-2..2,0..5) Equivalent to x has 4 rows (0 1 2 3).
y has 5 rows (-2 -1 0 1 2).
z has 6 rows (0 1 2 3 4 5 6).
So the length of the entire array is 4*5*6=120
-
The first dimension is 0 to3, the second dimension is -2 to 2, and the third dimension is 0 to 5, so 4*5*6=120
-
The points of study in this question:
1.Calculation of the total number of elements in a multidimensional array (equal to the product of the number of elements in each dimension)2The number of elements is known to be the upper and lower limits (the difference between the upper and lower limits + 1)3
The default upper limit value when the upper limit is not specified (is 0.)This can be adjusted using an option base statement (e.g., option base 1), but it is 0 by default).
Sum up. 1.The upper and lower limits of the 3-dimensional completion array: 0 3, -2 2, 0 52Calculate the number of elements per dimension: 3-0+1=4, 2-(-2)+1=5, 5-0+1=6
3.Multiply all: 4*5*6=120
120 is what is sought.