Answer to Question #191177 in C++ for python

Question #191177
1. Write a C++ program that will add two single dimensional array elements. Take values from user at runtime
1
Expert's answer
2021-05-18T02:49:20-0400
#include<iostream>
using namespace std;
int main()
{
	int Arr[100],n,i,sum=0;
	cout<<"Enter number of elements you want to insert ";
	cin>>n;
	for(i=0;i<n;i++)
	{
		cout<<"Enter element "<<i+1<<":";
		cin>>Arr[i];
	}
	for(i=0;i<n;i++)
		sum+=Arr[i];
	cout<<"\nThe sum of Array is :"<<sum;
	return 0;

}

Output:


Enter number of elements you want to insert 5
Enter element in ascending order
Enter element 1: 8
Enter element 2: 1
Enter element 3: 10
Enter element 4: 5
Enter element 5: 6

The sum of Array is :30

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment