Question

In: Computer Science

Write, specify and prove the function copy that copies a range of values into another array,...

Write, specify and prove the function copy that copies a range of values into another array, starting from the first cell of the array. First consider (and specify) that the two ranges are entirely separated. Note: Prototype is as below. void copy(int const* src, int* dst, size_t len){ }

Solutions

Expert Solution

Code for the function:

#include <stdio.h>
void copy(int const *src, int *dst, size_t len)
{
   int i;

   for (i = 0; i < len; ++i)
   {               //iterating len times
      *dst = *src; //copyting the valuaq1l of src pointer to dst pointer
      ++dst;       //incrementing destination pointer
      ++src;       //incrementing source pointer
   }
}

int main()
{
   int arr1[] = {1, 2, 3, 4, 5}; //first array
   int arr2[5];                  //declaring second array

   copy(arr1, arr2, 5); //calling the copy function

   int i;

   //testing the values in arr2 by printing them
   for (i = 0; i < 5; ++i)
   {
      printf("%d\n", arr2[i]);
   }
   return 0;
}


Output:

Code Screenshot:


Related Solutions

Write, specify and prove the function reverse that reverses an array in place. Take care of...
Write, specify and prove the function reverse that reverses an array in place. Take care of the unmodified part of the array at some iteration of the loop. Assume that the swap function is already proved. Note: Prototype is as below. [7 M] [CO2] void swap(int* a, int* b); void reverse(int* array, size_t len){ }
In C programming: Write a program that initializes an array-of-double and then copies the contents of...
In C programming: Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations: double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5}; double target1[5]; double target2[5]; copyarr(source, target1, 5);
Given an array labeled as array1 with the values: 11111h, 22222h, 33333h, 44444h And another array...
Given an array labeled as array1 with the values: 11111h, 22222h, 33333h, 44444h And another array labeled as array2 with the values: 0AEFFh, 23CAH, 1156H Sum up BOTH arrays through direct addressing and place the sum into the EAX register. array1 is a DWORD and array2 is a WORD
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
Using an array and a function, print the values of an array backwards. Please follow these...
Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything.
What is the function and argument to calculate the sum of the values in the range...
What is the function and argument to calculate the sum of the values in the range D1:D50 for which in the adjacent value in the range A1:A50 equals “Senior” and the adjacent value in the range B1:B50 equals “B”? What is the function and argument to calculate the average of the cells in the range C1:C50 for which the adjacent cell in the range B1:B50 equals “B”? What is the function and argument to return the index number of the...
Write a program that contains the following Write a function copies with two int parameters, named...
Write a program that contains the following Write a function copies with two int parameters, named n and x. It should dynamically allocate a new array of size n.  The function should then copy the value in x to every position in the array. The function should return a pointer to the new array. In the main function, call the copies function from part 1. with size 5 and value -1.  Output the resulting array to the screen, and deallocate the array....
In Java: Write a method called copy, which is passed A[], which is an array of...
In Java: Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of the first n items in A[]. Write a method called slice, which is passed A[], which is an array of int, an integer i and an integer j. The method returns a new array consisting of all of the items in A from A[i] to A[j] inclusive.
1) Write a function searchValue that accepts an array of integers, the size of the array,...
1) Write a function searchValue that accepts an array of integers, the size of the array, and an integer. Find the last occurrence of the integer passed in as an input argument in the array. Return the index of the last occurrence of the value. If the value is not found, return a -1 2) Write the line of code to call the previous function assuming you have an array vec with length n, and are looking for the number...
Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT