brel-logo-white brel-logo-white
  • Travel
  • Case Study
  • How to
  • Technology
  • More
    • Sports
    • Health
    • Articles
    • Review
Notification
  • HomeHome
  • Finance
  • Health
  • Lifestyle
  • Sports
  • Contact Us
BreldigitalBreldigital
  • HomeHome
  • Finance
  • Health
  • Lifestyle
  • Sports
  • Contact Us
Search
  • Quick Access
    • Home
    • History
    • My Saves
    • My Interests
    • My Feed
  • Categories
    • Travel
    • Sports
    • Health

Top Stories

Explore the latest updated news!

How many solutions exist for the given equation? 3x + 13 = 3(x + 6) + 1 zero one two infinitely many

What is a best practice when approaching an automation effort

How does using mynav allow accenture to help its clients become more sustainable?

Stay Connected

Find us on socials
248.1k Followers Like
61.1k Followers Follow
165k Subscribers Subscribe
Breldigital > Blog > ds > Sum of elements in an array
ds

Sum of elements in an array

By John Published November 10, 2022
Share

This is a C++ Program to Calculate Product and Sum of all Elements in an Array.

Problem Description
The program takes an array of elements and calculates the sum and product of all elements of the array.

Problem Solution
1. The program takes an array of elements and stores them in an array.
2. Using a for loop, the sum and product of the array are calculated.
3. The result is printed.
4. Exit.

C++ Program/Source code
Here is the source code of C++ Program to Calculate Product and Sum of all Elements in an Array. The program output is shown below.

#include
using namespace std;
int main ()
{
int arr[10], n, i, sum = 0, pro = 1;
cout << "Enter the size of the array : "; cin >> n;
cout << "\nEnter the elements of the array : "; for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < n; i++) { sum += arr[i]; pro *= arr[i]; } cout << "\nSum of array elements : " << sum; cout << "\nProduct of array elements : " << pro; return 0; } Runtime Test Cases Case 1 : Enter the size of the array : 5 Enter the elements of the array : 1 2 3 4 5 Sum of array elements : 15 Product of array elements : 120 Case 2 : Enter the size of the array : 11 Enter the elements of the array : 11 10 9 8 7 6 5 4 3 2 1 Sum of array elements : 66 Product of array elements : 39916800 Case 3 : Enter the size of the array : 3 Enter the elements of the array : 25 75 0 Sum of array elements : 100 Product of array elements : 0

TAGGED: Sum of elements in an array
John November 10, 2022 November 10, 2022

Search

brel-logo-white brel-logo-white
Explore a wide range of brands and categories with our comprehensive coverage, and stay up-to-date with the latest news and trends by subscribing to our updates.
Categories:
  • Entertainment
  • Travel
  • Sport
  • Contact Us

Quick Links

  • My Feed
  • My Interests
  • History
  • My Saves

About US

  • Adverts
  • Our Jobs
  • Term of Use

© 2023 Brel Digital All Rights Reserved. All logos and images used on this website are registered trademarks of their respective companies

Welcome Back!

Sign in to your account

Lost your password?