+ 1
Can someone help me to solve these questions
Write a function that receives an array, and check if it has the numbers 123 consequently or not. Such as an array {3,4,5,1,2,6} returns false, while array {4,5,1,2,3} returns true. Test function with an integer array from your own data. b. Write a function that takes two arrays s1, and s2, and return back if they are identical or not. Test function with an integer array from your own data.
10 Respuestas
+ 3
First of all, the functions both should return a boolean value.
The easiest solution for a) would be to loop over the array with a for-loop and check with an if-statement, e.g.
if (arr[i] == 1 && arr[i+1] == 2 && arr[i+2] == 3) { return true; }
If the condition hasn't triggered when the loop finishes, you return false instead.
Same for b), you can loop over the arrays with one for-loop and return false if their values differ at position x, and when the loop finishes, you return true.
It also might be a good idea to test the array sizes on equality beforehand for b).
In main(), you can just set up test arrays, call your functions on them and output the return value.
+ 3
You can directly output the return value using
cout << array( arr, 5 );
where arr is the name of the array.
+ 2
That way you will return true or false based on the very first check which will only test the third, fourth and fifth element.
+ 1
Of course we can help with this. What is it exactly that you are having trouble with when writing the functions? Maybe you can provide an attempt of yours that you are stuck with?
+ 1
I did. Hopefully it helps:
https://code.sololearn.com/cjAHsH1R3OX6/?ref=app
0
to be honest i want to know the structure of the function and the main because iam not sure if my answer or right ir not Shadow
0
i put it like
bool array( int a[],int size)
for (int i=0;i<5 ;i++){
if (a[2] ==1 && a[3]==2 && a[4]==3)
return true ;
else
return false;
}
Shadow
0
how can i call my function in the main?
int main(){
array ( , 5); // what should i put her?
cout << ??
0
can you write the whole 2 programmes? the important thing is the main
0
thank you so much❤️❤️❤️❤️