Saturday, 31 October 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



Ghanendra Yadav
Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In NIT Warangal And Also Working With WSDC( As Web Application Developer ) In NIT Warangal For Any Query Mail Me I Will Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment