Saturday, 30 January 2016

Merge Three Arrays In Fourth Array Problem Solution Using C++.


Soluton:

#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
 int ar1[1000],ar2[1000],ar3[1000],n,res[3000];
 cout << "How Many Elements You Want To Enter: ";
 cin >> n;
 cout << endl << "Enter Your First Array Elements (Separated By Space) : ";
 for(int i = 0; i < n; i++)cin >> ar1[i];
 cout << endl << "Enter Your Second Array Elements (Separated By Space) : ";
 for(int i = 0; i < n; i++)cin >> ar2[i];
 cout << endl << "Enter Your Third Array Elements (Separated By Space) : ";
 for(int i = 0; i < n; i++)cin >> ar3[i];
 
 for(int i = 0,j = 0; i < n; i++,j++){
  res[i] = ar1[i];
  res[i+n] = ar2[i];
  res[i+n+n] = ar3[i];
 }
 int sz = n*3;
 cout << endl << "Elements of Array After Merge: ";
 for(int i = 0; i < sz; i++)cout << res[i] << " ";
 cout << endl;
 return 0;
}

No comments:

Post a Comment