Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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

PREVIOUS NEXT
Code Example
Cpp :: class operator overloading c++ 
Cpp :: find function in c++ 
Cpp :: c++ integer array 
Cpp :: how to initialize a queue in c 
Cpp :: heap buffer overflow in c 
Cpp :: what do you mean by smallest anagram of a string 
Cpp :: c++ constructor call superclass 
Cpp :: visual studio cpp compiler 
Cpp :: cpp execute command 
Cpp :: udo apt install dotnet-sdk-5 permission denied 
Cpp :: prevent getting data from data-tooltip-content tippyjs 
Cpp :: how to change the value of a key in hashmp in c++ 
Cpp :: text color c++ 
Cpp :: C++ linked list iterator 
Cpp :: c++ get data type 
Cpp :: cpp vscode multipe compilation 
Cpp :: accumulate in cpp 
Cpp :: c++ pop string from vector 
Cpp :: how to create an integer in c++ 
Cpp :: C++ rename function 
Cpp :: Arduino Real TIme Clock 
Cpp :: remove element from c++ 
Cpp :: memset in cpp 
Cpp :: how to sort string array in c++ 
Cpp :: javascript if else exercises 
Cpp :: use declaration to define a variable 
Cpp :: auto in cpp 
Cpp :: gcd of two numbers 
Cpp :: how to bath without water 
Cpp :: simple program for sign in and sign up in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =