Sum of the elements of an array of integers

Given an array of integers, find the sum of its elements. Keeping in mind that some of those integers may be quite large.

Input Format

The first line contains an integer, ar_count, denoting the size of the array.
The second line contains space-separated integers representing the array’s elements.

Constraints

0<n, ar[i]<=1000

Output Format

Print the sum of the array’s elements as a single integer.

Function Description

The simpleArraySum function in the editor below returns the sum of the array elements as an integer.
simpleArraySum has the following parameter(s): ar: an array of integers

C Program

#include <stdio.h>
#include <stdlib.h>
int simpleArraySum(int ar_count,int ar[]) {
int t=0,SUM=0;
for(t=0;t<ar_count;t++)
{
SUM=SUM+ar[t]; //calculating the sum value
}
return SUM;
}
int main()
{
int ar_count,i,s;
scanf("%d",&ar_count); //Enter array size
int ar[ar_count];
for(i=0;i<ar_count;i++)
{
scanf("%d",&ar[i]); //Enter array elements
}
s=simpleArraySum(ar_count,ar); //store the sum value & call the provided function
printf("%d",s);
return 0;
}

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 *