In: Computer Science
C++
bool exists_trio(int*,int); (it must use this line here) I was not sure how to utilize this line because I made code that works but not with this line specifically.
//Input:
//an integer array (param 1) and its size (param
2)
//Output:
//True or false
//Behavior:
//Returns true is there exists
//a sequence of 3 *consecutive* values in the
array
//such that the sum of the first two elements
//is equal to the third element in that
//sequence, false otherwise.
//Example:
//For the array {3,4,1,3,17,3,20,21,5,96},
//the function returns true because of the
// sequence {17,3,20} (i.e., 17+3=20).
//For the array {3,4,1,3,3,7},
//the function returns false.
#include<iostream>
using namespace std;
bool exists_trio(int*,int);
int main(){
int arr1[]= {3,4,1,3,17,3,20,21,5,96};
int n1=10;
int arr2[]= {3,4,1,3,3,7};
int n2=6;
cout<<exists_trio(arr1,n1)<<endl;
cout<<exists_trio(arr2,n2)<<endl;
}
bool exists_trio(int *arr,int n){
for(int i=0;i<n-2;i++)
if(arr[i]+arr[i+1]==arr[i+2])
return 1;
return 0;
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME