CPP   28

array-index.cpp

Guest on 14th January 2022 10:33:36 AM

  1. #include <iostream> using namespace std;
  2.  void printArray(int a[], int size);
  3.  void printArray(int a[], int size){ for(int i=0;i<size;i++) { cout << i << " | "; cout << a[i] << endl; } cout << "_________" << endl; } void copyArray(int source[], int destination[], int size) { // Copy all the elements from the source to the destination. for(int i=0;i<size;i++) { destination[i]=source[i]; } } void reverseArray(int source[], int destination[], int size) { int d_index=0; int s_index=size-1; // Copy all the elements from the source to the destination. for(int i=0;i<size;i++) { destination[d_index]=source[s_index]; s_index--; d_index++; } } void initalizeArray(int destination[], int size, int value) { // Assign the value to all the elements int the destination. for(int i=0;i<size;i++) { destination[i]=value; } } int main() { int a[]={100,25,0,150}; int b[4]; int scores[5]; initalizeArray(scores,5,0);
  4. printArray(a,4); printArray(b,4);
  5. //printArray(a,sizeof(a)/sizeof(int));
  6.  printArray(a,4); cout << "Next array" << endl; reverseArray(a,b,4); printArray(b,4); cout << "Scores:" << endl; printArray(scores,5); return 0; }

Raw Paste


Login or Register to edit or fork this paste. It's free.