Answers for "how to reverse the elements of an array c++"

C++
3

reverse an array in c++

#include <iostream>
using namespace std;
int main()
{		// While loop
	const int SIZE = 9;
	int arr [SIZE];
	cout << "Enter numbers: n";
	for (int i = 0; i < SIZE; i++)
		cin >> arr[i];
	for (int i = 0; i < SIZE; i++)
		cout << arr[i] << "t";
	cout << endl;
	cout << "Reversed Array:n";
	int temp, start = 0, end = SIZE-1;
	while (start < end)
	{
		temp = arr[start];
		arr[start] = arr[end];
		arr[end] = temp;
		start++;
		end--;
	}
	for (int i = 0; i < SIZE; i++)
		cout << arr[i] << "t";
	cout << endl;	
  	return 0;
}
Posted by: Guest on January-12-2021
1

c++ program to reverse an array

#include<iostream>
using namespace std;
int main()
{
   int a[]={1,2,3,4,5};  // Using Pointer and Array Relationship
    for (int i = 4; i>=0; i--)
    cout<<*(a+i);
   return 0;
}
Posted by: Guest on May-12-2021
1

reverse an array in c++

#include <iostream>
using namespace std;
int main()
{
	const int SIZE = 9;
	int arr [SIZE];
	cout << "Enter numbers: n";
	for (int i = 0; i < SIZE; i++)
		cin >> arr[i];
	for (int i = 0; i < SIZE; i++)
		cout << arr[i] << "t";
	cout << endl;
	cout << "Reversed Array:n";
	int end = SIZE - 1, temp;
	for (int i = 0; i < end; i++)
	{
		temp = arr[i];
		arr[i] = arr[end];
		arr[end] = temp;
		end--;
	}
	/*	Reverse using while loop
	int temp, start = 0, end = SIZE-1;
	while (start < end)
	{
		temp = arr[start];
		arr[start] = arr[end];
		arr[end] = temp;
		start++;
		end--;
	}*/
	for (int i = 0; i < SIZE; i++)
		cout << arr[i] << "t";
	cout << endl;	
	}
Posted by: Guest on January-12-2021
0

reverse an array in cpp

#include<iostream>
using namespace std;
int main()
{   
     int n=3;
     int arr[]={1,2,3,4};
      while (n>=0)
    {
        cout<<arr[n];
        n--;
      }
         
    return 0;
}
Posted by: Guest on May-11-2021

Code answers related to "how to reverse the elements of an array c++"

Browse Popular Code Answers by Language