Visual Basic Programming!
How would you create an application that determines if a number entered by the user is a perfect square or not ?
The program code should include a PerfectSquare() Boolean function.
Hint: You can use the Int() function in determining if a square root is a whole number or not.
I'm learning programming with Visual Basic myself. Any help would be appreciated
回答 (2)
Private Function PerfectSquare(ByRef input As Double) As Boolean
Dim x As Integer
Return Integer.TryParse(Math.Sqrt(input), x)
End Function
Take the square root and copy that to another variable and take the int() value of that, but stored in a float.
Compare the two - if they are the same, it was a perfect square.
(Use float or double variables all the way through; I can't remember if VB has an "integer" type but avoid that if it has).
Or, take the square root, use int() on that then square again it (multiply by itself) and compare that to the original number.
收錄日期: 2021-04-24 00:11:03
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20170131065332AAV3yOH
檢視 Wayback Machine 備份