Answers for "transform c++"

C++
0

transform c++

// A C++ program uses transform() in STL to add 
// 1 to all elements of arr[]
#include <bits/stdc++.h>
using namespace std;
   
int increment(int x) {  return (x+1); }
   
int main()
{
    int arr[] = {1, 2, 3, 4, 5};
    int n = sizeof(arr)/sizeof(arr[0]);
   
    // Apply increment to all elements of
    // arr[] and store the modified elements
    // back in arr[]
    transform(arr, arr+n, arr, increment);
   
    for (int i=0; i<n; i++)
        cout << arr[i] <<" ";
   
    return 0;
}
Posted by: Guest on January-24-2022

Browse Popular Code Answers by Language