Question

In: Computer Science

/**Programming in C**/ Write a appendArray() function, whose parameters include two one-dimensional arrays of integers, arr1[]...

/**Programming in C**/

Write a appendArray() function, whose parameters include two one-dimensional arrays of integers, arr1[] and arr2[], with sizes size1 and size2, respectively. The function should append all of arr2 to the end of arr1 and return the updated size of arr1. int appendArray(int arr1[], int arr2[], int size1, int size2){

}

Are there any restrictions to the usability of your function when called from main() that should be included with the description of the function in the comments?

Solutions

Expert Solution

check out the solution and do comment if any queries.

-------------------------------------------------

#include<stdio.h>
#include<conio.h>
// function definition
// i think there are no restricions to call this function from 'main' as long as the type of variables remains as 'int'
int appendArray(int arr1[], int arr2[], int size1, int size2)
{
// declaration
int i, j;
// loop starts from the end of arr1 and start of arr2
for(i=size1, j=0; j<size2; i++, j++)
{
// append arr2 elements to the end of arr1
arr1[i] = arr2[j];
}
// print the updated arr1 elements
// and also 'i' contains the size of updated arr1 as it increments to get next arr1 element
printf("\nUpdated arr1 elements : \n\n");
for(i=0; i<size1+size2; i++)
{
printf("%d\t", arr1[i], i);
}

// returns the result as long as 'i' looped through arr1 to print updated arr1
return i;
}

// main function
int main()
{
// declaration
int size1, size2, size;
// initialization
size1 = 5;
size2 = 3;
int arr1[] = {1, 2, 3, 5, 6};
int arr2[] = {4, 5, 6};
// function call
size = appendArray(arr1, arr2, size1, size2);
// prints the updated arr1 size
printf("\n\n\nUpdated size of arr1 is : %d", size);

getch(); // optional statement
return 0;
}
// main ends

-------------------------------------------------------------

-----------------------------------------------

OUTPUT ::


Related Solutions

C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers...
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers called months and days to store the month and day of each date generated, a constant array of 12 integers called num_of_days that specify the number of days of each of the 12 months and an integer called size that specifies how many dates to generate and randomly generates size dates, storing the generated months in months array and generated days in days array....
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
One dimensional dynamic array Write a function that returns the number of integers in an input...
One dimensional dynamic array Write a function that returns the number of integers in an input file stream with the following interface: int findNumber(ifstream &x); Then, use this number to dynamically allocate an integer array. Write another function that reads each number in an input file stream and assign the value to the corresponding array element with the following interface: void assignNumber(ifstream &x, int y[ ]); In your main( ), first open “in.dat” as an input file. Next, apply findNumber(...
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
Write a C program whose input is two integers, and whose output is the first integer...
Write a C program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a...
In C++ write a function to find a product of two matrices using arrays. The function...
In C++ write a function to find a product of two matrices using arrays. The function should be general and should accept any size matrices.
In C++, write a program that uses two identical arrays of ten randomly ordered integers. It...
In C++, write a program that uses two identical arrays of ten randomly ordered integers. It should display the contents of the first array, then call a function to sort it using the most efficient descending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using descending order selection sort, modified to print out the...
Write a recursive function named multiply that takes two positive integers as parameters and returns the...
Write a recursive function named multiply that takes two positive integers as parameters and returns the product of those two numbers (the result from multiplying them together). Your program should not use multiplication - it should find the result by using only addition. To get your thinking on the right track: 7 * 4 = 7 + (7 * 3) 7 * 3 = 7 + (7 * 2) 7 * 2 = 7 + (7 * 1) 7 *...
In C++, write a function that takes in as inputs two arrays, foo and bar, and...
In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT