Sum of an array in c || Sum of array Elements in C

Sum of an array in c

Example 1

#include <stdio.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5}; // Declare and initialize an array of 5 integers
    int sum = 0;
    int i;
    
    // Calculate the sum of the elements in the array
    for (i = 0; i < 5; i++) {
        sum += arr[i];
    }
    
    // Print out the sum
    printf("The sum of the elements in the array is: %d", sum);
    
    return 0;
}

User Define

Sum of an array in c

Example 2

#include<stdio.h>
int main(){
int arr[10],i,sum=0;

for(i=0;i<10;i++){
        scanf("%d",&arr[i]);
    //printf("%d ",arr[i]);
    sum=sum+arr[i];
}
for(i=0;i<10;i++){
    printf("%d ",arr[i]);
}
printf("\n sum is %d",sum);
}


Sum of array Elements in C

Program To Find Cube In C

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck