Saturday, 31 October 2015

C++ Program To Reverse An Array Sum Of Its Element

Problem :- Program to read 1-D array ,Display its elements in reverse order and print the sum of the elements . 

Logic :- You can print array element from last index to zero'th index and add all element of array check here how to reverse element in array C++ Program To Reverse An Array In O(n)

Solution :-

#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:-

C++ Program To Reverse An Array Sum Of Its Element

No comments:
Write comments

Recommended Posts × +