Answer to Question #346451 in C++ for Ali

Question #346451

Write a program that declares 2 integer arrays x, y of size 10 each. The program then reads values for x and y arrays from the user (use some common values).



Finally the program finds the common values in x and y and prints them. If there is no common values in x and y print “There is nothing common between array x and y”.




1
Expert's answer
2022-05-30T15:14:05-0400
#include <iostream>


using namespace std;


int main() {
    int x[10], y[10];
    int element, flag = 0;


    cout << "Input X elements" << endl;
    for (int i = 0; i < 10; i++) {
        cin >> x[i];
    }


    cout << "Input Y elements" << endl;
    for (int i = 0; i < 10; i++) {
        cin >> y[i];
    }
    
    cout << "Common values:" << endl;
    for (int i = 0; i < 10; i++) {
        element = x[i];
        for (int j = 0; j < 10; j++) {
            if (element == y[j]) {
                flag = 1;
                cout << element << " ";
                break;
            }
        }
    }


    if (flag == 0) {
        cout << "There is nothing common between array x and y" << endl;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Ali
31.05.22, 06:05

I like your source code.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS