Tech Study

Write a Swift program to find the larger value of a given array of integers and set all the other elements with that value

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 newarray(_ arra: [Int]) -> [Int] {
    var new_arra = arra
 
    if new_arra.first! > new_arra.last!
     {
        new_arra[1] = new_arra.first!
        new_arra[2] = new_arra.first!
     } 
    else 
     {
        new_arra[0] = new_arra.last!
        new_arra[1] = new_arra.last!
     }
    return new_arra
}
print(newarray([1, 4, 6]))
print(newarray([2, 5, 9]))
print(newarray([3, 8, 8]))

Result

Write a Swift program to find the larger value of a given array of integers and set all the other elements with that value
Write a Swift program to find the larger value of a given array of integers and set all the other elements with that value

TaggedWrite a Swift program to find the larger value of a given array of integers and set all the other elements with that value

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