//Script by aakash30jan
<script type="text/vbscript">
For count = 1 to 10
sum=sum+count
document.write("<br />" & sum)
Next
</script>
Chat with our AI personalities
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
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)
find even number in array
One place to find information on visual basic coding is a local library. The website msdn microsoft has extensive tutorials and guides on visual basic coding.
First you will need to have some basic programming knowledge. You can use this to help make the program that is needed.
bwiset
Tutorials for Visual Basic can be found on MSDN Microsoft, Amos Development, and Home and Learn UK. The Engineering Department at Auburn University also offers a very detailed tutorial for Visual Basic.