কম্পিউটার

C++ এ হার্ডকোড এলিমেন্ট সহ একটি std::vector আরম্ভ করার সবচেয়ে সহজ উপায় কি?


আধুনিক C++ [11,14,…] এ একটি ভেক্টরকে নিম্নলিখিত পদ্ধতিতে শুরু করা হয়

std::vector<int> vec = {1,2,3};

অ্যালগরিদম

Begin
   Initialize the vector v.
   Using accumulate, sum up all the elements of the vector v is done.
   Print the result.
End.

এখানে একটি ভেক্টরের উপাদানগুলির যোগফলের একটি সহজ উদাহরণ:

উদাহরণ

#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main() {
   vector<int> v = {2,7,6,10};
   cout<<"Sum of all the elements are:"<<endl;
   cout<<accumulate(v.begin(),v.end(),0);
}

আউটপুট

Sum of all the elements are:
25

  1. লিনাক্সে C++ এর সেরা IDE কি?

  2. লিনাক্সে c++ এর জন্য শীর্ষ IDE কি?

  3. উইন্ডোতে c++ এর জন্য শীর্ষ IDE কি?

  4. জাভাতে একটি স্ট্রিং বিপরীত করার সবচেয়ে সহজ উপায় কি?