Question

c++ write a boolean function that accepts two integer arrays of size 10 as input parameters,...

c++ write a boolean function that accepts two integer arrays of size 10 as input parameters, the function should return true if there are any similar values between the two arrays and shall return false if not, if there are similar values, print out on screen

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

bool findSimilarValues(int a[], int b[]) {
bool result = false;
for(int i=0;i<10;i++) {
for(int j=0;j<10;j++){
if(a[i] == b[j]) { //find any similar value
cout<<a[i]<<"(index " << i <<" of 1st array) and " <<a[j]<<"(index " << j << " of 2nd array)" <<endl;
result = true;
}
}
}
return result;
}

int main() {
int a[10],b[10];
cout<<"Enter 1st array: "<<endl;
for(int i=0;i<10;i++){
cin>>a[i];
}
cout<<"Enter 2nd array: "<<endl;
for(int i=0;i<10;i++){
cin>>b[i];
}
cout<<findSimilarValues(a,b);


}

Add a comment
Know the answer?
Add Answer to:
c++ write a boolean function that accepts two integer arrays of size 10 as input parameters,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ write a function that has 3 parameters, two arrays of integers of the same size...

    c++ write a function that has 3 parameters, two arrays of integers of the same size , and the size of the arrays. the function should add the two arrays and store the results in a third array, then print out the contents of the third array name it arraya

  • In C++ 1.Define a function named "sumCodes" that accepts two input parameters: "s "and "pos". "s"...

    In C++ 1.Define a function named "sumCodes" that accepts two input parameters: "s "and "pos". "s" is an object of the type "string" and "pos" is a boolean value with the default argument of "true". If "pos" is "true", the function returns the summation of the ASCII codes of all the characters located at the even indices of "s" and if "pos" is "false", the function returns the summation of the ASCII codes of all the characters located at the...

  • Write a program with a function named isEqualArr that accepts a pair of arrays of integers...

    Write a program with a function named isEqualArr that accepts a pair of arrays of integers as parameters and returns true if the arrays contain the same elements in the same order. If the arrays are not the same length, your function should return false. For example, if the following arrays are declared: int[] arr1 = {10, 20, 30, 40, 50, 60}; int[] arr2 = {10, 20, 30, 40, 50, 60}; int[] arr3 = {20, 3, 50, 10, 68}; The...

  • Write a function with two input parameters: an array of numbers and the size of the...

    Write a function with two input parameters: an array of numbers and the size of the array (the number of elements). The function should return the count of even numbers in the array. For example, if the input to the function is the array [3, 2, 45, 56, 12], the function would return the integer 3. Use the following function header: int countEvens(int nums[], int size) { }

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • The method generate() will produce integer arrays of a random size between 10 and 20 members. ...

    The method generate() will produce integer arrays of a random size between 10 and 20 members. The method print() will print out the members of an integer array input. The method insert() will accept two arrays as inputs. It will produce a new array long enough to contain both arrays, and both input arrays should be inserted into the new array in the following manner: select a random member of the first array, and insert every member of the second...

  • Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is...

    Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is a two dimensional array. The function should add the first two arrays a and b (entry by entry), storing the results in the third array c. In the main function, call the add function with appropriate values. The main function should print the sum of the two arrays stored in the third array. Sample run: float al...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • (devC++) Develop a C recursive function that accepts an integer N. The function should calculate and...

    (devC++) Develop a C recursive function that accepts an integer N. The function should calculate and return the result of the following function: f(N) = 1 + 1/2! + 1/3! + ...+1/N! Write a C program that reads an integer value. The program should call the function above and then print the result on the screen with two decimal point format (i.e. 12.34).

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT