Blog Kumpulan Tugas

Jumat, 17 Juni 2016

Menggabungkan 2 Array

#include <iostream>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void print (int*, int);
int* gabung(int*, int, int*, int);

int main(int argc, char** argv) {


int a[]={11,22,33,44,55};
    int b[]={66,77,88,99};
    cout <<"Array A dengan 5 elemen: ";print(a,5);
    cout <<"Array B dengan 4 elemen: ";print(b,4);
    int* c=gabung(a,5,b,4);
    cout <<"Setelah digabung [A B]: ";print(c,9);
}
int* gabung(int* a, int m, int* b, int n){
    int* c= new int[m+n];
    for (int i=0; i<m; i++)
        c[i]=a[i];
    for (int i=m; i<m+n; i++)
        c[i]=b[i-m];
    return c;
}
Share:

1 komentar:

  1. Grand Casino Resort – Casino, Resort & Spa - Mapyro
    Welcome to Grand Casino Resort. 전라북도 출장안마 This 구리 출장마사지 25,000 sq. ft. casino is an 18 story, 40 story high-rise in Casino of the 제천 출장마사지 Gods. It features a 과천 출장샵 24-story tower with 제주도 출장마사지

    BalasHapus

Diberdayakan oleh Blogger.

Blog Archive