How to add elements in an array using C Program.

Add elements of an Array :

ElementsToArray.c
#include<stdio.h>
int main(void)
{
    int arr[10],i,total=0;
    for(i=0; i<10; i++)
    {
        printf("Enter value for arr[%d] : ",i);
        scanf("%d",&arr[i]);
        total+=arr[i];
    }
    printf("Total : %d\n",total);
    return 0;
}

 

Output:

Terminal
Enter value for arr[0] : 10
Enter value for arr[1] : 20
Enter value for arr[2] : 30
Enter value for arr[3] : 40
Enter value for arr[4] : 50
Enter value for arr[5] : 60
Enter value for arr[6] : 70
Enter value for arr[7] : 80
Enter value for arr[8] : 90
Enter value for arr[9] : 100
Total : 550

Happy Learning 🙂

About the Author:

Founder of onlinetutorialspoint.com Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

Leave A Comment