কম্পিউটার টিউটোরিয়াল

সি-তে একবারের বেশি বার আসা অ্যারে উপাদান



একটি অ্যারেতে যেসব উপাদানের ফ্রিকোয়েন্সি ১ এর বেশি সেগুলো বের করতে হবে। উদাহরণ: {1,5,2,5,3,1,5,2,7} → ১ (২ বার), ৫ (৩ বার), ২ (২ বার)। আউটপুট: {1,5,2}

অ্যালগরিদম

moreFreq(arr, n)

Begin define map for each e in arr do increase map[e] done for each key if map[key] > 1 then print key End

উদাহরণ

#include <iostream> #include <map> using namespace std; void moreFreq(int arr[], int n){    map<int,int> freq_map;    for(int i=0; i<n; i++) freq_map[arr[i]]++;    for (auto it=freq_map.begin(); it!=freq_map.end(); it++) {       if (it->second > 1) cout << it->first << " ";    } } int main() {    int arr[] = {1,5,2,5,3,1,5,2,7};    int n = sizeof(arr)/sizeof(arr[0]);    cout << "Frequency more than one: ";    moreFreq(arr, n); }

আউটপুট

Frequency more than one: 1 2 5

  1. C++-এ K-এর গুণিতকের মাঝপথে থাকা অ্যারে এলিমেন্ট সর্ট করা

  2. অ্যারে (বিগুণ সংখ্যা) এর GCD বের করা (C++)

  3. C++-এ দুইটির অধিক সংখ্যার GCD (GCD of Array/Multiple Numbers)

  4. দুটির চেয়ে বেশি (অথবা অ্যারে) সংখ্যার GCD বের করার জাভা প্রোগ্রাম