answersLogoWhite

0

//Script by aakash30jan

<script type="text/vbscript">

For count = 1 to 10

sum=sum+count

document.write("<br />" & sum)

Next

</script>

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
ReneRene
Change my mind. I dare you.
Chat with Rene
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
More answers

The sum of the first n natural numbers is a recursive function such that f(n) is f(n-1)+n for all values n >1 where f(1) is 1. Although the function is naturally recursive, an iterative implementation would prove more efficient:

Function sum_naturals(ByVal num As UInteger) As UInteger

sum_naturals = 0

While (num > 0)

sum_naturals = sum_naturals + num

num = num - 1

End While

End Function

Sub Main()

Console.Write("The sum of all naturals 1 to 42 is: ")

Console.WriteLine(sum_naturals(42))

End Sub

User Avatar

Wiki User

9y ago
User Avatar

You never specified what do you mean by 'n' numbers.

to get a sum of two numbers, assign both to value

(ex: dim num1 as integer = textbox1.text

dim num2 as integer = textbox2.text )

or another example:

dim num1 as integer = 2398

dim num2 as integer = 2989

now write:

label1.text = num1 + num2

for the output (answer) to appear on label1

to make it appear in a msgbox do

msgbox(num1 + num2)

or

dim num3 as integer = num1 + num2

msgbox(num3)

and for a more good looking way:

msgbox( "the answer is: " & num3)

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: A program to find the sum of n numbers in visual basic?
Write your answer...
Submit
Still have questions?
magnify glass
imp