Program to read the 1D array, Display its elements in reverse order and print the sum of the elements
Explanation:-
You can print array element from the last index to zero'th index and add all elements of an array and while you are reversing the array also add all variables of an array and keep the sum in and at the end of the program print the sum of all variable of an array. .
#include<iostream>
using namespace std;
int main()
{
int a[100],i,n,sum=0;
cout<<"Enter The Size of Array\n";
cin>>n;
cout<<"Enter Element Of Array\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Elment in Array is Given Below\n";
for(i=(n-1);i>=0;i--)
{
cout<<a[i]<<" ";
sum=sum+a[i];
}
cout<<"\n\nSum Of Array Is = "<<sum;
return 0;
}
Output:
Enter The Size of Array
5
Enter Element Of Array
10
20
30
4
5
Elment in Array is Given Below
5 4 30 20 10
Sum Of Array Is = 69
need an explanation for this answer? contact us directly to get an explanation for this answer