iota() in C++

iota(): This function is available in the file stl_numeric.h. This function creates a range of sequentially increasing values. For each element in the range [first, last) assigns value and increments value as if by ++value. 

Parameters: Three parameters are required for this function.

 __first – Start of range.

 __last – End of range.

 __value – Starting value. 

Returns: Nothing.

Syntax:

iota(__first , __last, __value)

For Example:

vector<int>arr (10)

iota(arr.begin(),arr.end(),10)  => It insert 10 elements in the array arr start from 10 to 19

arr ={10,11,12,13,14,15,16,17,18,19}

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr(10);
    iota(arr.begin(), arr.end(), 10);
    

    for (int i = 0i < arr.size(); i++)
        cout << arr[i] << " ";

    return 0;
}


No comments:

Post a Comment