天天看點

答複: 畫圖時遇到的問題?可以說是一個算法題吧。

Sub f1()

m = InputBox("Please enter your number!")

For i = 1 To m

For j = 1 To m

If i = j Then ' 對角線

Cells(i, j).Value = i * i

Cells(i, j).Interior.ColorIndex = 35

End If

If i > j Then ' 下三角

Cells(i, j).Value = i * (i - 1) + j

Cells(i, j).Interior.ColorIndex = 28

End If

If i < j Then ' 上三角

Cells(i, j).Value = (j - 1) * (j - 1) + i

Cells(i, j).Interior.ColorIndex = 14

End If

Next j

Next i

End Sub

繼續閱讀