
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C/C++ Program to find the sum of elements in a given array
Sum of all Array elements means add all array Elements. Suppose we have 5 Elements in array and we want to find there sum.
arr[0]=1 arr[1]=2 arr[2]=3 arr[3]=4 arr[4]=5
Sum off all above elements are
arr[0]+arr[1]+arr[2]+arr[3]+ arr[4]=1+2+3+4+5=15
Input:1,2,3,4,5 Output:15
Explanation
Using For loop to get to the every index element and taking sum of them
arr[0]+arr[1]+arr[2]+arr[3]+ arr[4]=1+2+3+4+5=15
Example
#include <iostream> using namespace std; int main() { int i,n,sum=0; int arr[]={1,2,3,4,5}; n=5; for(i=0;i<n;i++) { sum+=arr[i]; } cout<<sum; return 0; }
- Related Articles
- Program to find sum of elements in a given array in C++
- Swift Program to Calculate the sum of Elements in a Given Array
- Write a Golang program to calculate the sum of elements in a given array
- How to find the sum of all elements of a given array in JavaScript?
- C++ program to find permutation for which sum of adjacent elements sort is same as given array
- Java program to find the sum of elements of an array
- Construct sum-array with sum of elements in given range in C++
- Golang Program to find the odd-occurring elements in a given array
- C Program to find sum of perfect square elements in an array using pointers.
- Program to find sum of given sequence in C++
- Write a Golang program to find duplicate elements in a given array
- Program to find sum of the 2 power sum of all subarray sums of a given array in Python
- C# program to print all distinct elements of a given integer array in C#
- C++ Program to find Number Whose XOR Sum with Given Array is a Given Number k
- Find Sum of all unique subarray sum for a given array in C++

Advertisements