Answer to Question #307538 in C for Silas

Question #307538

Write a program to find the sum of array elements


1
Expert's answer
2022-03-07T16:42:49-0500
int main()
{
    int sum;
    int i, n;
    int array[] = {1, 3, 5, 6, 9, 11, 5, 2, 1, 21, 23, 25, 3, 5, 7, 9, 11, 13, 26, 28};
    n = sizeof(array)/sizeof(array[0]);
    // if enter the array manually
    //
    // printf("Enter N: ");
    // scanf("%d", &n);
    // int array[n];
    // printf("Enter array: \n");
    // for (i = 0; i < n; i++)
    //       scanf("%d", &array[i]);
    sum = 0;
    printf("\nArray:\n");
    for(i=1; i < n; i++)
    {
        printf("%d ", array[i]);
        sum = sum + array[i];
    }   
    printf("\n\nSum of array elements: %d ", sum);
   
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS