Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

sum of an array

const sum = (...args) => args.reduce((a, b) => a + b, 0);
console.log(sum(1,2,3)); // returns 6
Comment

arrays.sum

int sum = Arrays.stream("1 2 3 4".split("s+")).mapToInt(Integer::parseInt).sum();
Comment

sum of arrays

/**
 * C program to find sum of all elements of array
 */

#include <stdio.h>
#define MAX_SIZE 100

int main()
{
    int arr[MAX_SIZE];
    int i, n, sum=0;

    /* Input size of the array */
    printf("Enter size of the array: ");
    scanf("%d", &n);

    /* Input elements in array */
    printf("Enter %d elements in the array: ", n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &arr[i]);

        // Add each array element to sum
        sum += arr[i];
    }

    printf("Sum of all elements of array = %d", sum);

    return 0;
}
Comment

sum of arrays

/**
 * C program to find sum of all elements of array 
 */

#include <stdio.h>
#define MAX_SIZE 100

int main()
{
    int arr[MAX_SIZE];
    int i, n, sum=0;

    /* Input size of the array */
    printf("Enter size of the array: ");
    scanf("%d", &n);

    /* Input elements in array */
    printf("Enter %d elements in the array: ", n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &arr[i]);
    }

    /*
     * Add each array element to sum
     */
    for(i=0; i<n; i++)
    {
        sum = sum + arr[i];
    }


    printf("Sum of all elements of array = %d", sum);

    return 0;
}
Comment

sum of array

int sumofarr(int *a, int n) {
	if (n>1)
        return a[n-1]+sumofarr(a, n-1);
    return a[0];
}
Comment

sum of array value

$total = 0;
foreach ($products as $product) {
    $subtotal = $product['price']*$product['quantity'];
    $total += $subtotal;
}

echo $total;
Comment

PREVIOUS NEXT
Code Example
Java :: java double to float 
Java :: spring security after login redirect 
Java :: how to get cpu model number in android programmatically 
Java :: Java get color from rgb values 
Java :: java get element occurrences in a list java 
Java :: how to create hashmap 
Java :: abstract method declaration 
Java :: traversing treemap in java 
Java :: Remove an element at a specific index from an array in Java 
Java :: java.lang.IllegalStateException: Could not obtain identifier 
Java :: java try-with-resources 
Java :: java array of array 
Java :: int to char java 
Java :: MyLinkedList 
Java :: how to convert a string of characters to a stream of binary characters binary 
Java :: sort list of list java 
Java :: integer parse int exceptions 
Java :: Number formatting java with locale 
Java :: stack initialization for string java 
Java :: java xml element get attribute value 
Java :: observer pattern java 
Java :: java class array of objects 
Java :: types of methods in java 
Java :: Add an element to ArrayList using addall() method 
Java :: android get app build name 
Java :: inheritance in java 
Java :: Create EntityManager Hibernate 
Java :: refresh sharedpreferences going back java 
Java :: hibernate onetone with mapsid 
Java :: greatest of three in java 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =