Doubling an array?
Oct 30, 2011 at 11:43pm UTC
I'm almost done with this assignment, i just can't figure out how to double the original array, and the unused elements of the second array have to be initialized with 0. I left the last function with a return 0, and that's where i'd like to double the array. Here's my code, Thanks!:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include<iostream>
#include<cstdlib>
using namespace std;
void populateArr(int * a, int size);
void printArr(int * a, int size);
int * doubleArray(int * old, int size);
int main()
{
int * arr, arrX2; //two pointers
int size; //variable
cout<< "Enter size of an array: " ;
cin >> size;
arr = new int [size];
populateArr(arr, size);
printArr(arr, size);
system("pause" );
return 0;
}
void populateArr(int * a, int size)
{
int * arr = 0;
for (int i=0;i<size;i++)
{
a[i] = rand()%51;
}
}
void printArr(int a[], int size)
{
for (int k=0;k<size;k++)
{
cout << a[k] << endl;
}
cout << "-------------------" << endl;
cout << "size= " << size << endl;
cout << "-------------------" << endl;
}
int * doubleArray(int * old, int size)
{
return 0;
}
Last edited on Oct 30, 2011 at 11:47pm UTC
Oct 31, 2011 at 1:08am UTC
bump. can anyone help me out?
Topic archived. No new replies allowed.