Simple Array Sum

Sort by

recency

|

3468 Discussions

|

  • + 0 comments
    def simpleArraySum(ar):
        
        SumAr = 0 
        for x in ar : 
            
            SumAr+=x
            
        return SumAr
            
    
  • + 0 comments

    In C

    #include <stdio.h>
    
    
    int arraySum(int size, int vector[]) {
    
        int sum = 0;
        for (int i = 0; i < size; i++) {
            sum = sum + vector[i];
        }
        
        return sum;
    }
    
    int fillVector (int vector[], int size) {
        
        int number;
        
        for (int i = 0; i < size; i++) {
            scanf("%d", &number);
            vector[i] = number;
        } 
       
       int result = arraySum(size, vector);
       
       return result;
    }
    
    int main() {
        int size;
        
        scanf("%d", &size);
        
        int vector[size];
        
        int result = fillVector(vector, size);
        
        printf("%d",result);
        
        return 0;
    }
    
  • + 0 comments

    This is not about the problem itself but, there is anyone having trouble submitting your solutions? I've been trying for ages and keep getting an error message. Does anyone know why?

  • + 0 comments

    Thanks for the solutions, they make the array-sum concept much clearer! I’m also exploring how to adapt this logic for a real project — specifically on my WordPress site for an Insurance service page. Has anyone here tried reusing these algorithms in practical web applications?

  • + 0 comments

    in javascript :

    let sum = 0
        for(let i=0 ; i < ar.length ; i++){
            sum += ar[i]
        }
        return sum