how to display a array elements in a listbox in c# code example

Example 1: bash display items in array

$ printf '%s\n' "${my_array[@]}"

Example 2: add all elements in array javascript

console.log(
  [1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
  [].reduce((a, b) => a + b, 0)
)

Example 3: how to delete an element from an array in java

import java.util.Scanner;

public class ElemRemoval {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] intArr = {1, 2, 5, 12, 7, 3, 8};
        System.out.print("Enter Element to be deleted : ");
        int elem = in.nextInt();
        
        for(int i = 0; i < intArr.length; i++){
            if(intArr[i] == elem){
                // shifting elements
                for(int j = i; j < intArr.length - 1; j++){
                    intArr[j] = intArr[j+1];
                }
                break;
            }
        }
      
        System.out.println("Elements -- " );
        for(int i = 0; i < intArr.length - 1; i++){
            System.out.print(" " + intArr[i]);
        }                
    }
}

Example 4: insert elements in array in c++11

int main() {
    int array[10];
    for(int &i : array){
        std::cin >> i;
    }
}

Tags:

Cpp Example