This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

18 Aug 2013

VB.Net Program to Print Sum Of Series 1+2+3+..+n

Module Module1

    Sub Main()
        Dim sum As Integer = 0, i As Integer, n As Integer
        Console.WriteLine("*** www.programmingposts.blogspot.com ***")
        Console.WriteLine(vbLf & ">>> VB.Net Program to print Sum of Series 1+2+3+..+n <<<")
        Console.Write(vbLf & " Enter the nth number of series: ")
        n = Convert.ToInt32(Console.ReadLine()) 'taking input, converting to Int
        For i = 1 To n
            sum += i 'calculating sum 
        Next
        Console.WriteLine(vbLf & " Sum of series upto  {0} is : {1}", n, sum)
        Console.ReadLine()
    End Sub

End Module

Sample Output: 


No comments:

Post a Comment

Thanks for your comments.
-Sameer