Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C++

C++ में transform_inclusive_scan() फंक्शन


इस ट्यूटोरियल में, हम C++ में transform_inclusive_scan() फंक्शन को समझने वाले प्रोग्राम पर चर्चा करेंगे।

उदाहरण

#include <iostream> #include <vector> using namespace std; namespace point_input_iterator {    template <class InputItrator, class OutputItrator, class BinaryOperation, class UnaryOperation>    OutputItrator transform_inclusive_scan(InputItrator first,       InputItrator last,       OutputItrator d_first,       BinaryOperation binary_op,       UnaryOperation unary_op){             *d_first = unary_op(*first);       first++;       d_first++;       for (auto it = first; it != last; it++) {          //प्रीफिक्स सम की गणना          *d_first = binary_op(unary_op(*it), *(d_first - 1));          d_first++;       }       return d_first;    } } int main(){    वेक्टर का उपयोग करके एलिमेंट्स इनपुट करना    vector<int> InputVector{ 11, 22, 33, 44, 55, 66, 77, 88 };    vector<int> OutputVector(8);    point_input_iterator::transform_inclusive_scan(InputVector.begin(), InputVector.end(), OutputVector.begin(), [](auto xx, auto yy) {       return xx + yy;    },    [](auto xx) {       return xx * xx;    });    for (auto item : OutputVector) {       //आउटपुट आइटम प्रिंट करना       cout << item << " ";    }    cout << std::endl;    return 0; }

आउटपुट

121 605 1694 3630 6655 11011 16940 24684

  1. - C++ में transform() फ़ंक्शन

    परिचय transform फ़ंक्शन C++ STL (स्टैंडर्ड टेम्पलेट लाइब्रेरी) में मौजूद है। इसका उपयोग करने के लिए हमें <algorithm> हेडर फाइल शामिल करनी होती है। यह फ़ंक्शन सभी एलिमेंट्स पर एक ऑपरेशन करने के लिए उपयोग किया जाता है। उदाहरण के लिए, यदि हम एक ऐरे के प्रत्येक एलिमेंट का वर्ग निकालकर दूसरे ऐरे मे

  1. - C++ में log() फ़ंक्शन

    C/C++ लाइब्रेरी फ़ंक्शन double log(double x) x का नेचुरल लॉगरिदम (बेस e लॉगरिदम) लौटाता है। log() फ़ंक्शन के लिए घोषणा निम्नलिखित है। double log(double x) पैरामीटर एक फ्लोटिंग पॉइंट मान है। और यह फ़ंक्शन x का नेचुरल लॉगरिदम लौटाता है। उदाहरण #include <iostream> #include <cmath> using

  1. - C++ में swap() फ़ंक्शन

    swap() फ़ंक्शन दो संख्याओं को स्वैप (अदला-बदली) करने के लिए उपयोग किया जाता है। तीसरे वेरिएबल की आवश्यकता नहीं होती। <algorithm> या <utility> हेडर में परिभाषित (C++11 से)। सिंटैक्स void swap(Type& a, Type& b); उदाहरण 1: मान द्वारा पास (मान बदलते नहीं) #include <bits/stdc++.