Sunday, September 18, 2011

Appends one array to another and print them in C++

In the following program, show how to append or add one array to another.

#include <iostream>

using namespace std;

int* append(int*, int, int*, int);
void print(int*, int);
int main()

    int a[] = {11,22,33,44,55};
    int b[]={66,77,88,99};
    int* c= append(a,5,b,5);

int* append(int* a, int m, int*b, int n)
    int* c= new int[m+n];
    for (int i=0; i<m;i++)
    for(int i=m;i<m+n;i++)
    return c;

void print(int* a, int n)

    cout <<"{" << a[0];
    for (int i=1;i<n;i++)
    cout << "," << a[i];
    cout << "} \n";

0 comments em “Appends one array to another and print them in C++”

Post a Comment

Give your valuable Comment...


Programming, Data Structures & Algorithms Copyright © 2011 -- Template created by JAK -- Powered by Blogger