# Sum of the elements of an array in C

By: Ignatius Emailed: 1728 times Printed: 2329 times

 By: rohit kumar - how this program is work By: Kirti - Hi..thx for the hadoop in By: Spijker - I have altered the code a By: ali mohammed - why we use the java in ne By: ali mohammed - why we use the java in ne By: mizhelle - when I exported the data By: raul - no output as well, i'm ge By: Rajesh - thanx very much... By: Suindu De - Suppose we are executing

This simple C program computes the sum of all the elements of an array.

``` ```

``````#include <stdio.h>
#define   SIZE  12

int main()
{
// declare and initialize the array named a with size SIZE
int a[SIZE] = {1,3,5,4,7,2,99,16,45,67,89,45};
// declare two normal variables
int i, total = 0;
// do the loop for the array...
for(i = 0; i <= (SIZE-1); i++)
{
// display the array and its element...
printf("\n a[%d]= %d", i, a[i]);
// total up the array
// total = total + a[i]
total += a[i];
}
printf("\nThe sum of the array elements is %d\n", total);
return  0;
}
``````
``` ```

Be the first one to add a comment

Your email(required, will not be shown to the public):

More Tutorials by Ignatius
 Sorting an array of Strings in C++ Sorting an integer array in C Printing a simple histogram in C Sum of the elements of an array in C Matrix using nested for loops in C++ Compute the square root of the sum of the squares of an array in C++ Calculate average using Two-Dimensional Array in C++ Two-Dimensional Array Manipulation in C++

More Tutorials in C
 Sum of the elements of an array in C Printing a simple histogram in C Sorting an integer array in C Find square and square root for a given number in C Simple arithmetic calculations in C Command-line arguments in C Calculator in C Passing double value to a function in C Passing pointer to a function in C Infix to Prefix And Postfix in C while, do while and for loops in C Unicode and UTF-8 in C Formatting with printf in C if, if...else and switch statements in C with samples Statements in C

More Latest News
Most Viewed Articles (in C )
 Using memset(), memcpy(), and memmove() in C goto and labels in C Find square and square root for a given number in C Open, Creat, Close, Unlink system calls sample program in C Using calloc() Function in C perror() Function - example program in C Sorting an integer array in C Character Arrays in C scanf and sscanf sample program in C lseek() sample program in C Arrays sample program in C register Variables in C Arrays of Structures example program in C union example program in C fgets(), fputs() - Line Input and Output - sample program in C
Most Emailed Articles (in C)
 Listing Files and Directories sample program in C Arithmetic Operators in C Relational and Logical Operators in C Increment and Decrement Operators in C register Variables in C File Inclusion in C Pointers and Function Arguments in C Pointers and Arrays in C Character Pointers and Functions in C Pointer Arrays and Pointers to Pointers in C Multi-dimensional Arrays in C (Explained using date conversion program) Initialization of Pointer Arrays in C The Birth and history of C Programming Language Basics of C Getting Started with C