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
|
/*
Suppose you have declared two arrays, A and B in a program.
Array A already has values in it, and the number of values is stored in N.
Write a function to copy the N values in A to B. Write the calling statement also.
Store the values from A to B in reverse order.*/
#include <iostream>
#include <iomanip>
using namespace std;
void revCopyArray (int [], int [], int);
int main()
{
int A [10] = { 14, 35, 8, 10, 99, -1, 654, 12, 0, 33 };
int B [10];
revCopyArray (B, A, 10);
for ( int sub = 0; sub< 10; sub++)
{
cout << B [sub] <<endl;
}
return 0;
}
void revCopyArray (int copyIntoArray[], int copyFromArray[], int numValues )
{
for (int sub = 0; sub2 = numValues -1; sub < numValues; sub++, sub2--)
{
copyIntoArray[sub] = copyFromArray[sub2];
}
}
|