Sum of the elements in an array

Given an array of integers, find the sum of its elements.

Input Format

The first line of the input consists of an integer.
The next line contains space-separated integers contained in the array.

Output Format

Return the integer sum of the elements in the array.

Constraints

1<=n<=10
0<=ar[i]<=10^6

Function Description

The aVeryBigSum function in the editor below returns the sum of all array elements.
aVeryBigSum has the following parameter(s): int ar[n]: an array of integers.
Return:
long: the sum of all array elements.

C Program

#include <stdio.h>
#include <stdlib.h>
long aVeryBigSum(int ar_count, long ar[]) {
int i;
long int sum=0;
while (i<ar_count) {
sum=sum+ar[i];
i++;
}
return sum;
}
int main()
{
int ar_count,i=0;
long int s;
scanf("%d",&ar_count);
long int ar[ar_count];
while (i<ar_count) {
scanf("%ld",&ar[i]);
i++;

}
s= aVeryBigSum( ar_count, ar);
printf("%ld",s);
}

Related Posts

CSS Cheatsheet

Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…

HTML Cheatsheet

Unleash your web development potential with my HTML cheatsheet! Elevate your coding skills, master essential tags and attributes, and build stunning websites with ease. Whether you’re a…

Git&GitHub Cheatsheet

Elevate your Git and GitHub game with my ultimate cheatsheet! Unlock the power of version control, streamline collaboration, and boost productivity. Navigate the complexities of Git commands…

Command Line Cheatsheet

Master the Command Line effortlessly with my comprehensive cheatsheet! Streamline your workflow, boost productivity, and become a command line guru. Unlock essential commands, shortcuts, and tips to…

OpenAI’s APIs Notes

Unlock the potential of OpenAI’s APIs with my comprehensive notes! Dive into the world of cutting-edge artificial intelligence, explore the capabilities of GPT-4 and beyond, and learn…

SQL Notes

Discover the essence of SQL with my comprehensive notes! Dive into the world of Structured Query Language, unraveling the complexities, and mastering database management. Elevate your SQL…

Leave a Reply

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