Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int * arrExpand(int*, int );
- int * arrShift(int*, int);
- void printArr(int*, int);
- int main(){
- int *firstArr, *secArr, *arr, arrSize;
- cout<<"What is the size of the array? ";
- cin >> arrSize;
- for(int i = 0; i < arrSize; i++){
- cout<<"Enter element #" << i+1<< ": ";
- cin>>arr[i];
- }
- firstArr = arrExpand(arr, arrSize);
- secArr = arrShift(arr, arrSize);
- printArr(firstArr, (arrSize * 2));
- printArr(secArr, (arrSize + 1));
- delete [] arr;
- }
- int * arrExpand(int *arr, int arrSize){
- int *newArr = new int [arrSize * 2];
- if(newArr == NULL)
- cout<<"No more memory"<<endl;
- for(int i = 0; i < arrSize; i++){
- newArr[i] = arr[i];
- }
- for(int j = arrSize; j < (arrSize * 2); j++){
- newArr[j] = 0;
- }
- return newArr;
- }
- int * arrShift(int *arr, int arrSize){
- int *newArr = new int [arrSize + 1];
- newArr[0] = 0;
- for(int i = 1; i < (arrSize + 1); i++){
- newArr[i] = arr[i-1];
- }
- return newArr;
- }
- void printArr(int *arr, int size){
- for(int i = 0; i < size; i++)
- cout << arr[i] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement