Use C programming
Swap two arrays using pointers
Given two integer arrays, swap the two arrays using pointers.
Input:
4
1 2 3 4
5
4 5 6 7 8
where:
Output:
4 5 6 7 8
1 2 3 4
#include <stdio.h> #include <stdlib.h> int main(void) { int s1, s2; int i; scanf("%d", &s1); int *arr1 = malloc(sizeof(int) * s1); for(i=0; i<s1; i++) { scanf("%d", &arr1[i]); } scanf("%d", &s2); int *arr2 = malloc(sizeof(int) * s2); for(i=0; i<s2; i++) { scanf("%d", &arr2[i]); } // now both arrays are read in arr1 and arr2. // now swap pointers. int *temp = arr1; arr1 = arr2; arr2 = temp; // print for(i=0; i<s2; i++) { printf("%d ", arr1[i]); } printf("\n"); for(i=0; i<s1; i++) { printf("%d ", arr2[i]); } printf("\n"); return 0; }
Please upvote, as i have given the exact answer as asked in
question. Still in case of any issues in code, let me know in
comments. Thanks!
Use C programming Swap two arrays using pointers Given two integer arrays, swap the two arrays...
Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...
C programming Strictly - Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. Problem 1 (68 points): Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. The code should contain the following functions: 1)to randomly generate an array of integer numbers; 2) to allocate memory and build the arrays of pointers as shown in the figure...
input: Task3: Given two int arrays, output true if the two arrays are identical and false if they are not. Input: task3 input Output: Array 1: 2 3 1 6 7 8 1 3 9 5 Array 2: 5 4 7 9 3 2 4 1 6 2 False 10 ܕ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ ܃ : : 7 s a
Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1....
Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...
using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...
Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...
Write a C program that inputs 5 elements into each of 2 integer arrays. Add corresponding array elements, that array1 [0] + array2[0], etc. Save the sum into a third array called sumArray[]. Display the sum array. Submit your and the input and output of the complete execution.
C- PROGRAMMING PROJECT #4 Design and Write a C program to calculate an average of an array of numbers and produce the following output: 1. Your first and last name 2. Course Number 3. C Project Number 4. All the numbers in the array 5. The sum of all the numbers in the array 6. The count of all the numbers in the array 7. The average of all the numbers in the array Double-space after lines 3, 4, 5,...
1. Write a program that reads in two arrays (a1 and a2) of numbers and creates a new array (a3) of numbers such that the new array contains all the unique numbers of a1 and a2. Assume the input array elements are unique elements. In the main function, ask the user to enter the length of each array, declare and reads in the numbers for each array, and calculate and display the output array. Example input/output #1: Enter the length...