Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. int*doubleSize(const int*, int);
  3. int* reverseArray(int [], int);
  4. int main()
  5. {
  6.     const int size = 3;
  7.     int array [size];
  8.     int* twice;
  9.     int* reverse;
  10.     std::cout <<"Enter" << size << "elements for the array";
  11.     for(int j=0; j <size;j++)
  12.     {
  13.         std::cin >>array[j];
  14.     }
  15.     for(int i =0; i < size; i++)
  16.     {
  17.         std::cout << "Original array list:" <<" " <<array[i] << " ";
  18.         std::cout <<std::endl;
  19.     }
  20.    
  21.     twice = doubleSize(array,size);
  22.    
  23.     std::cout << "Duplicated array with list with zeros filled for the unused elements";
  24.     for(int k=0; k < size*2;k++)
  25.     {
  26.         std::cout << "\n" << twice[k];
  27.     }
  28.     std::cout <<std::endl;
  29.    
  30.     reverse = reverseArray(array,size);
  31.     std::cout << "Reversed array:";
  32.     for(int l=0; l <size*2;l++)
  33.     {
  34.         std::cout << reverse[l];
  35.     }
  36.    
  37.    
  38.     return 0;
  39. }
  40. int* doubleSize(const int* array, int size)
  41. {
  42.     int* twice = new int[size*2];
  43.    
  44.     for(int i =0; i<size*2;i++)
  45.     {
  46.         if(i < size)
  47.         {
  48.             twice[i]= array[i];
  49.         }
  50.         else
  51.             twice[i]=0;
  52.        
  53.    
  54.     }
  55.    
  56.    
  57.    
  58.         return twice;
  59.    
  60. }
  61. int* reverseArray(int array[],int size)
  62. {
  63.     int* newArray = new int[size*2];
  64.    
  65.     int j =0;
  66.     for(int i = ((size*2)-1); i >=0; i--)
  67.     {
  68.         newArray[j] = array[i];
  69.         j++;
  70.     }
  71.     return newArray;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement