Tech Study

Write a Swift program to compute the sum of all the elements of a given array

Introduction

I have used Swift for windows 1.9 for debugging purpose. But you can use any Swift programming language compiler as per your availability.

func sumofnumbers(_ arra: [Int]) -> Int {
    return arra.reduce(0, +)
}
print(sumofnumbers([-7, 5, 2, 0]))
print(sumofnumbers([3, 4, 5, 8]))
print(sumofnumbers([2, 6, 2, 1]))

Result

Write a Swift program to compute the sum of all the elements of a given array
Write a Swift program to compute the sum of all the elements of a given array

TaggedWrite a Swift program to compute the sum of all the elements of a given array

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more

Function Pointer in C++

Introduction : Function Pointer in C++ Pointers: In function pointer in c++ are the variables that consist of addresses of …

Read more