Code:
#include <iostream>
using namespace std;
//to swap elements of array
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
//to sort the array
void sort(int a[], int n)
{
int i,j;
for(i = 0; i < n; i++)
{
int min = i;
for(j = i+1; j < n; j++ )
if(a[j] < a[min])
min = j;
swap(&a[min], &a[i]);
}
}
//to check if the element already exists
bool ifExists(int a[], int el, int n)
{
for(int i = 0; i < n; i++)
if(a[i] == el)
return true;
return false;
}
int main()
{
int a1[100], a2[100], res[100], n1, n2, nres = 0;
//receive user input
cin >> n1;
for(int i = 0; i < n1; i++)
cin >> a1[i];
cin >> n2;
for(int i = 0; i < n2; i++)
cin >> a2[i];
//adding element if common and does not exist already in resultant array
for(int i = 0; i < n1; i++)
{
for(int j = 0; j < n2; j++)
{
if((a1[i] == a2[j]) && (!ifExists(res, a1[i], nres)))
res[nres++] = a1[i];
}
}
//sorting resultant array
sort(res, nres);
cout << "resulting array is : ";
for(int i = 0; i < nres; i++)
cout << res[i] <<" ";
return 0;
}

Output:

4. Write a C++ program (or Java program) w that reads two groups of numbers in...
Write a Java program that reads in a positive integer from the user and outputs the following triangle shape composed of asterisk characters. For example, if user enters 5 as the input, then your program should display the following shape: ***** **** *** ** *
Task 1 : Write a Java program that prompts for and reads 10 integers from the user into an integer array of size 10, it then: - calculates the sum and average of positive numbers of the array and displays them. [Note: consider 0 as positive] Note: The program must display the message: "There are no positive values" if the array does not contain any positive value.
Write a C program that reads a sequence of numbers and display a message 1. The numbers a re red from the standard input. 2. The first number is the length of the sequence (n) followed by n numbers. 3. If n is 0 or negative, the program displays the message "Error_1" followed 4. If the length is shorter than n, it displays "Error_2" followed by a new line 5. The program inspects the list and display one of the...
In C++: Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The list is preceded by an integer indicating how many numbers are in the list. If the input is: 5 10 5 3 21 2, the output is: 2 3 To achieve the above, first read the integers into a vector.
In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...
Write a Java program called EqualSubsets that reads a text file, in.txt, that contains a list of positive and negative integers (duplicates are possible) separated by spaces and/or line breaks. Zero may be included. After reading the integers, the program saves them in a singly linked list in the same order in which they appear in the input file. Then, without changing the linked list, the program should print whether there exists two subsets of the list whose sums are...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to input 10 int numbers from the user...
JAVA. Write a program that reads in a series of positive integers and prints out the maximum value entered. The user will indicate they are finished entering numbers by entering zero or a negative integer.
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to...
C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...