Module SumArFunc Sub Main() Dim n, i, s As Integer Console.Write("Enter Number of elements: ") n = CInt(Console.ReadLine()) Dim arr(n) As Integer Console.WriteLine() For i = 0 To n - 1 Console.Write("Enter Element (" + (i + 1).ToString() + ")= ") arr(i) = CInt(Console.ReadLine()) Next Console.WriteLine() Console.WriteLine("Array") Console.WriteLine("-------------") For i = 0 To n - 1 Console.WriteLine("Array (" & i & ")= " & arr(i)) Next Console.WriteLine("-------------") s = sum(arr, n) Console.WriteLine("Sum of Elements= " & s.ToString()) Console.ReadLine() End Sub Function sum(ByVal x() As Integer, ByVal y As Integer) Dim j, s1 As Integer s1 = 0 For j = 0 To y - 1 s1 += x(j) Next Return s1 End Function End Module
Visual Basic dot net VB.net programming microsoft .net framework object oriented language network enabled technology visual basic 2005 IDE integrated development environment console application microsoft cre common runtime environment
Summation of elements of an array Using Function
Subscribe to:
Post Comments (Atom)
tthank u
ReplyDelete