Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do you use square roots in Visual Basic?

I need an example of how to display the squares of the numbers 1 - 10 to the console output window. I can't find any information to assist me. Newbie to the world of programming.

Update:

Thank you very much, and I have noticed that. I thought the command Console.Readkey would show the output until I hit a key. It does work better if I use MsgBox. Thanks for your help.

Update 2:

What is the Next x used for. I haven't seen that in my notes.

Update 3:

I was able to get it to work, once I cleared the syntax errors. Thank you gentleman, now all I have to do is understand what the heck I'm doing. LOL

2 Answers

Relevance
  • Anonymous
    1 decade ago

    To answer your question you would use a For - Next statement like so:

    dim y as integer

    For i As Integer = 1 to 10

    y = x ^ 2

    WriteToConsole y

    Next x

    Here is the problem though. By default visual basic does not want to output to console as it is meant to be a GUI based language. You can force it too but that becomes a rather complex task. Therefore I recommend printing the results to a GUI instead.

  • 1 decade ago

    imports System.math;

    public void test()

    {

    For i As Integer = 0 To 10

    Console.WriteLine(Math.Pow(i, 2))

    Next

    }

    it isn't work ???

Still have questions? Get your answers by asking now.