#Swift programming language
• For each:
Implement a function forEach(array: [Int], _ closure: Int -> ()) that takes an array of integers and a closure and runs the closure for each element of the array.
Example:
var array = [1,2,3,4]
forEach(array) { print($0 + 1) }
forEach(_:)
Calls the given closure on each element in the sequence in the same order as a for-in loop.
Program:
let array = [1,2,3,4]
array.forEach { print($0+1) }
Output:
Program:
let array = [1,2,3,4]
array.forEach { i in
print(i)
}
Output:
#Swift programming language • For each: Implement a function forEach(array: [Int], _ closure: Int -> ())...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...
CODE MUST BE WRITTEN IN SWIFT programming language Write a function that takes in two positive integers and prints every prime number between (and including) them Sample Input: prime(from: 0, to: 100) Sample Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
the programming language is in java Problem 2 You are given an array A with n distinct elements. Implement an (n log n)-time algorithm that creates an array B where all elements are in range from 0 to n - 1 and where the order of elements is the same as in A. That is, 0 has the same index in B as the smallest element in A, 1 has the same index in B as the second smallest element...
In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...
C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...
Need to implement an IterativeMax function in assembly language using the MIPS calling convention. IterativeMax take two arguments: The address of an array of word-long (four byte) signed integers, held in $a0. The length of the array as an unsigned integer, held in $a1. The main purpose of the function is to determine which element of the provided array is the largest (i.e., the maximum element in the array). This is achieved by going through the array one element at...
implement void Quick_Sort(int A[],int l,int r) to sort array of integers in ascending order using the first element as a pivot, you can add any parameter you want Note : you are only allowed to use java language
Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...
Implement a function called rightrotate(int src[4][4], int dst[4][4]) that rotates the values in the src array 90 degrees to the left and stores it in the dst array. (See example below). Save your program in a file called Q4.cpp and save it in Question #4. YOU MUST USE LOOPS FOR THIS QUESTION! src 1,2,3,4 5,6,7,8 9,0,1,2 3,4,5,6 dst 4,8,2,6 3,7,1,5 2,6,0,4 1,5,9,3
In Lisp programming language a 16. (20 pts.) Write a function that takes a list of 0's and l's and "toggles" each element. Your function should include lambda expression that knows how to flip an individual element, plus an applicative operator to do this to every element of the list. Example: 1 0) List (0 0 1 1 0 1) should be transformed into (1 1 0 0