Question

C++. Write a program that copies the contents of one array into another array but in...

C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.

          - in main()

                   - define 2 arrays of type int, 10 elements each

                             - initialize one array with numbers 1 through 10

                             - initialize all elements of the second array to 0

                   - call function reverseCopy with both arrays as arguments

                   - display the values of array number 2 (reversed order)

          - reverseCopy function

                   - use pointers ONLY to reference the elements of the arrays

                             - no array subscripts allowed!!!

                    - use a loop to copy the elements of array 1 into array 2

                             - in reverse order

                                      - element 10 of array 1 copied to element 1 of array 2

                                      - element 9 of array 1 copied to element 2 of array 2

                                      - and so on till all elements are copied

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

void reverseCopy(int arr1[10],int arr2[10])

{

int j=0;

for(int i=9;i>=0;i--)

{

*(arr2+j) = *(arr1+i);

j++;

}

  

printf("Content of array 2 : ");

for(int i=0;i<10;i++)

printf("%d ",*(arr2+i));

}

int main()

{

int arr1[10] = {1,2,3,4,5,6,7,8,9,10};

int arr2[10] = {0,0,0,0,0,0,0,0,0,0};

reverseCopy(arr1,arr2);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
C++. Write a program that copies the contents of one array into another array but in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • Can someone help me understand this step by step (C++) Array Shifter and Array Reversal Write...

    Can someone help me understand this step by step (C++) Array Shifter and Array Reversal Write a function that accepts an array of doubles and the array's size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Done in C++ using visual studio 1. Write a program with one additional function called int[]...

    Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...

  • 7eatng that function Write a C++ program that does the following: Fill an array of 123...

    7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program...

    Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program #5-5). Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count. <END>

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT