31/10/2015

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

Problem:- Program to read the 1D array, Display its elements in reverse order and print the sum of the elements or easier way to reverse array c++ or c++ reverse array elements or how to print an array backward in c or print array in reverse order java or print 2n lines in reverse order c++ or print array in reverse order javascript or c++ program for printing 2n lines in reverse sequence or how to print the content of a file in reverse order in c++.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.


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. check here how to reverse element in array C++ Program Reverse An Array In O(n).

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post.

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 And Sum Of Its Element


You May Also See


1. C++ Program To Check Number Is Positive Or Negative

2. C++ Program To Find Character Is Vowel Or Not

3. C++ Program To Calculate Factorial Of A Given Number



Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: