Input a list if integers, just like last time, then input a second list. Put the first list in array a, the second in array b. Let counta be the number of integers in a, and countb the number of integers in b. Your task is to print all numbers that occur in both lists. Like last time, you must loop over array a, and decide whether to print a[i] or not. If a[i] occurs in array b, from b[0] to b[countb-1] inclusive, then print a[i]; otherwise not.
Code:
#include <iostream> using namespace std; int a[30] int b[3] int counta, countb, n; int k,j; int main () { int used_number; cout<<"Enter the first list of numbers\n"; cin>> k; for (k=0; k>=20; k++) { cin>> a[k]; if a[k]==0 return k; } for (k=0; used_number=k+1) { for (j=(k+1); J=used_number+1; j++ { if a[k]==a[j] a[j]=[-2] } } for (k=0; k= used_number+1;k++) { if a[k]==[-2] cout<< a[k]; } bool find (int a[k], int size, target) { int k; for(k=0; k<size;k++ ) { if (a[k]==target) return true } return false } for (k=0;k<countb; k++) { found= find (a, counta, b[k]); if (found) cout<< b[k]<< "0"; } return 0; }
Comment