Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will store 7 integers (entered by the user) into an array c

ID: 3569473 • Letter: W

Question

Write a program that will store 7 integers (entered by the user) into an array ca lled "list1". Next, prompt the user for 5 integers and put them into an array called "list2". Now, list all of the numbers that are in BOTH lists. Below is a sample run. NOTE: Include a functio n called "getNumber" which asks the user for a number, then RE TURNS it to calling function (in this case, "main").

List 1

------

Enter an integer: 4

Enter an integer: 2

Enter an integer: 7

Enter an integer: 1

Enter an integer: 5

Enter an integer: 6

Enter an integer: 3

List 2

------

Enter an integer: 11

Enter an integer: 9

Enter an integer: 7

Enter an integer: 5

Enter an integer: 3

The numbers that are in both lists are:

3, 5, 7

NOTE: DO NOT USE GLOBAL VARIABLES!!!!! A global variable is a variable that is defined outside of any function (including ma in). We don't cover them in this co urse because they are generally a very bad idea. So, don't do this in your projects!

Explanation / Answer

#include<iostream>
using namespace std;
int getnumber()
{
int k;
cin>>k;
return k;
}
int main()
{
int list1[7],list2[5],i,j;
cout<<"list1"<<endl;
for(i=0;i<7;i++)
{
cout<<"Enter an Integer: ";
list1[i]=getnumber();
}
cout<<"list2"<<endl;
for(i=0;i<5;i++)
{
cout<<"Enter an Integer: ";
list2[i]=getnumber();
}

for(i=0;i<5;i++)
{
for(j=0;j<7;j++)
{
if(list2[i]==list1[j])
{
if(i==0)
cout<<"Numbers in both list are: ";
cout<<list2[i]<<" ,";
break;
}
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote