Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

reverse function in cpp array

// C++ program to reverse Array
// using reverse() in STL
 
#include <algorithm>
#include <iostream>
using namespace std;
 
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
 
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
 
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
 
    // Reverse the array
    reverse(arr, arr + n);
 
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

reverse an array in c++ stl

//Reverse an array using C++ STL
#include <algorithm>  //Header file for reverse method

 int arr[] = { 1, 2, 3, 4, 5 };
 int n = sizeof(arr) / sizeof(arr[0]);  //Size of array
 reverse(arr, arr + n);
 //Now array looks like = { 5, 4, 3, 2, 1 }
 //The time complexity is O(n)

//https://www.linkedin.com/in/kalyan-santra-44589a126/
Comment

stl function to reverse an array

reverse(ar , ar + n) ; //ar is the array , n is the size
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

c++ Write a program to reverse an array or string

// Iterative C++ program to reverse an array
#include <bits/stdc++.h>
using namespace std;
 
/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
    while (start < end)
    {
        int temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}    
 
/* Utility function to print an array */
void printArray(int arr[], int size)
{
   for (int i = 0; i < size; i++)
   cout << arr[i] << " ";
 
   cout << endl;
}
 
/* Driver function to test above functions */
int main()
{
    int arr[] = {1, 2, 3, 4, 5, 6};
     
    int n = sizeof(arr) / sizeof(arr[0]);
 
    // To print original array
    printArray(arr, n);
     
    // Function calling
    rvereseArray(arr, 0, n-1);
     
    cout << "Reversed array is" << endl;
     
    // To print the Reversed array
    printArray(arr, n);
     
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: toupper c++ 
Cpp :: c++ program to find lcm of two numbers 
Cpp :: count sort algorithm 
Cpp :: initialize a vector to 0 
Cpp :: c++ inheritance 
Cpp :: cpp get exception type 
Cpp :: run c++ program mac 
Cpp :: calculator in cpp 
Cpp :: visual studio cpp compiler 
Cpp :: how to grab numbers from string in cpp 
Cpp :: install qpid broker in ubuntu/linux 
Cpp :: how creat matrix column in c++ 
Cpp :: convert ascii char value to hexadecimal c++ 
Cpp :: create new node in tree 
Cpp :: string erase 
Cpp :: c++ little endian or big endian 
Cpp :: c++ json parser euc-kr 
Cpp :: opencv compile c++ 
Cpp :: call function from separate bash script 
Cpp :: c++ online compiler 
Cpp :: int cpp 
Cpp :: find first of a grammar 
Cpp :: c++ check if number is even or odd 
Cpp :: c++ define function pointer 
Cpp :: create vectors of vectors c++ 
Cpp :: how to modify 2d array in function c++ 
Cpp :: c++ allocate dynamic with initial values 
Cpp :: front priority queue cpp 
Cpp :: c++ tuple push_back 
Cpp :: CPP print executable name 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =