var names = new Array("Mary", "Tom", "Jack", "Jill");
function disp(arr_names) {
for (var i = 0; i < arr_names.length; i++) {
console.log(names[i]);
}
}
disp(names);
//Mary
//Tom
//Jack
//Jill
function myFunction(a, b, c) {//number of parameters should match number of items in your array
//simple use example
console.log("a: " + a);
console.log("b: " + b);
console.log("c: " + c);
}
var myArray = [1, -3, "Hello"];//define your array
myFunction.apply(this, myArray);//call function
function test([a, b])
{
console.log(a);
console.log(b);
}
function run()
{
test(["aaaaa", "bbbbbbb", "cccccc", "ddddddd", "eeeee"])
}
/*note that not every element was used in the function*/
// Program to calculate the sum of array elements by passing to a function
#include <stdio.h>
float calculateSum(float num[]);
int main() {
float result, num[] = {23.4, 55, 22.6, 3, 40.5, 18};
// num array is passed to calculateSum()
result = calculateSum(num);
printf("Result = %.2f", result);
return 0;
}
float calculateSum(float num[]) {
float sum = 0.0;
for (int i = 0; i < 6; ++i) {
sum += num[i];
}
return sum;
}