Question

In: Computer Science

Please Answer with C code and I will rate! Thank you. Problem) Write a program that...

Please Answer with C code and I will rate! Thank you.

Problem) Write a program that reads 20 integers and stores them in two arrays of 10 elements
each. Then, the program should check if the two arrays have common elements, if yes,
the program should displays the value of each common element and its position in both arrays. Otherwise,
it should display a message and that their elements are different.

Solutions

Expert Solution

#include<iostream>

using namespace std;

int main()

{

    int i, j;

   

    // create arrays of size 10

    int arr1[10];

    int arr2[10];

   

    cout<<"Enter 10 numbers : ";

   

  // read elements in first array

    for( i = 0 ; i < 10 ; i++ )

        cin>>arr1[i];

       

    cout<<"\nEnter 10 numbers : ";

   

    // read elements in second array

    for( i = 0 ; i < 10 ; i++ )

        cin>>arr2[i];

       

    // store the number of common elements

    int count = 0;

   

    // traverse first array

    for( i = 0 ; i < 10 ; i++ )

    {

        int index = -1;

       

        // travserse array 2 to find common elements with i th element of array 1

        for( j = 0 ; j < 10 ; j++ )

        {

            // if the jth element is common

            if( arr1[i] == arr2[j] )

                index = j;

        }

       

        // if the i th element is common

        if( index != -1 )

            cout<<arr1[i]<<" is common and occurs at index "<<i<<" in 1st array and index "<<index<<" in 2nd array."<<endl;

    }

   

    return 0;

}


Sample Output


Related Solutions

Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
You cna hand write this if you want, Please code this in C Thank you PROBLEM...
You cna hand write this if you want, Please code this in C Thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement:...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output a string that is the concatenation of string str1...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
Please answer using MSP design and program for C. Write CCS code. outline the program for...
Please answer using MSP design and program for C. Write CCS code. outline the program for MSP design, and program for C. Make a project that uses one timer on the board to control the blinking of the LED. Basically setup a timer interupt. Whenever the timer interrupt happens, the LED blinks. The frequency of the blinking is chosen by the user. Next modify the program above and make a project that uses one of the pushbuttons on the board...
PROBLEM: c++ code You are to write a program to tell you how many months it...
PROBLEM: c++ code You are to write a program to tell you how many months it will take to pay off a loan, as well as the total amount of interest paid over the life of the loan. You have just purchased a stereo system that costs $1000 on the following credit plan: No down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT