Given an array “A”, your task is to find the sum of the elements in the array.
Perform the same using 2 different methods:
Part 1: Get the size of the array, get the array elements by using an input dialog activity, and perform the sum operation.
Part 2: Get a number “N” and find the sum of the first “N” elements from the array.Please do share the how to create this work flow
Hope the below steps would help you resolve this
Say you have a variable named arr_numbers of type array of int32
Now use a assign activity to get the sum of all elements in that array
int_output = Convert.ToInt32(YourArrayVar.Sum(function (x) CDbl(x)))
Where int_output is a variable of type int32
- For the second method to get the sum of N numbers
int_output_2 = Convert.ToInt32(YourArrayVar.Take(N).Sum())
How to get the Size of array and number of elements of array from Input dialogue box from user
Size of array is
int_size = Arrayvariable.Count
And for number of elements we want We can have that in a variable named Strinput from input dialog box and pass it like this
int_sum = Convert.ToInt32(YourArrayVar.Take(Convert.ToInt32(Strinput)).Sum())