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 of array 1: 5
Enter the elements of the array: 8 4 1 3 9
Enter the length of array 2: 3
Enter the elements of the array: 5 4 8
Output array: 8 4 1 3 9 5
Example input/output #2:
Enter the length of array 1: 4
Enter the elements of the array: 3 4 1 7
Enter the length of array 2: 2
Enter the elements of the array: 6 9
Output array: 3 4 1 7 6 9
#include <iostream>
using namespace std;
void uniqueElement(int a1[], int a2[],
int a, int b)
{
int j = 0,i = 0, k = 0;
while (i < a && j < b)
{
if (a1[i] <
a2[j])
{
cout << a1[i] << " ";
i++; k++;
}
else if (a2[j] <
a1[i]) {
cout << a2[j] << " ";
k++; j++;
}
else {
i++; j++;
}
}
while (i < a) {
cout << a1[i]
<< " ";
i++; k++;
}
while (j < b) {
cout << a2[j]
<< " ";
j++; k++;
}
}
int main()
{
int a,b,i,j;
int a1[10];
int a2[10];
cout<<"Enter the length of array 1";
cin>>a;
cout<<"Enter the elements of array 1";
for(i=0;i<a;i++)
{
cin>>a1[i];
}
cout<<"Enter the length of array 2";
cin>>b;
cout<<"Enter the elements of array 2";
for(j=0;j<b;j++)
{
cin>>a2[j];
}
cout<<"Output array:";
uniqueElement(a1, a2, a, b);
return 0;
}

1. Write a program that reads in two arrays (a1 and a2) of numbers and creates...
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...
Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...
Write a java method merge that accepts two arrays of integers and returns a new array containing all elements of the first array followed by all elements of the second. int[] a1 = {12, 34, 56}; int[] a2 = {7, 8, 9, 10}; int[] a3 = merge(a1, a2); System.out.println(Arrays.toString(a3)); // [12, 34, 56, 7, 8, 9, 10]
write the solution of the program by python 3 language : I need the program using list : You are given a sequence of n positive integers a1,a2,…,an, where n is even. Swap adjacent elements in the given sequence and print the resulting sequence: a2,a1,a4,a3,a6,a5,… Input The first line contains a positive even integer n (2≤n≤1000) — the length of the sequence. The second line contains n space-separated integers a1,a2,…,an (1≤ai≤1000) — the elements of the sequence. Output Print n...
Write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above the average. Make sure to include pointer syntax. Example output: Enter array size: 10 10 random numbers between 1 and 10 generated are: 2 8 5 1 10 5 9 9 3 5 The average is: 5.7 Number of items above the average = 4 C++ Code only.
(C programming) Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a contiquous subsequence. Input The input consists of multiple datasets. Each data set consists of: n a1 a2 . . an You can assume that 1 ≤ n ≤ 5000 and -100000 ≤ ai ≤ 100000. The input end with a line consisting of a single 0. Output...
Please and thank you
2) (5 pts) Arrays & Vectors: write a program which prompts the user to enter numbers (terminated with a non-numeric), reads them simultaneously into an array of doubles and into a vector of doubles, then prints A) the array elements in the original order B) the vector elements in reverse order C) the average of the vector elements D) the largest of the vector elements Example program output, user input shown underlined Enter a list of...
Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data: 2 1 4 9 16 9 7 4 9 11 Then it computes 2 - 1 + 4 - 9 + 16 - 9 + 7 - 4 + 9 – 11 = 4 Use a scanner object to gather the inputs from the user....
Write a program to merge two sorted arrays into a third array. Ask the user to enter the size of the two arrays. The length of array1 could be greater than, equal to or less than the length of array2. Fill both with random numbers 0-99. Sort both arrays as explained below. Write a method merge that takes the two arrays as arguments. The method returns a merged array with size equal to the size of both arrays combined. Note:...
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: First line represents the number of elements in the first array. Second line represents the elements in the first array. Third line represents the number of elements in the second array. Fourth line represents the elements in the second array. Output: 4 5 6 7...