added a function for add elements in an array