Question

In: Computer Science

C++ bool exists_trio(int*,int); (it must use this line here) I was not sure how to utilize...

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.

Solutions

Expert Solution

#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


Related Solutions

I was not sure how to utilize this line because I made code that works but...
I was not sure how to utilize this line because I made code that works but not with this line specifically. C++ Function 2: bool exists_trio_within_distance(int*,int,int); //Input:    //an integer array (param 1), its size (param 2), and    //a distance (param 3) //Output:    //True or false //Behavior:    //Returns true is there exists    //a sequence of 3 values in the array    //such that sum of the first two elements    //is equal to the third element...
Use python There is a revenue list, how to covert it from string to int? Here...
Use python There is a revenue list, how to covert it from string to int? Here is the list ['$8,120,000,000', '$8,085,200,000', '$7,703,000,000', '$7,000,000,000', '$5,410,000,000', '$4,212,000,000', '$3,741,400,000', '$3,500,000,000', '$3,000,000,000', '$2,800,000,000', '$2,800,000,000', '$2,529,000,000', '$2,087,600,000', '$2,000,000,000', '$1,900,000,000', '$1,520,000,000', '$1,500,000,000', '$1,500,000,000', '$1,350,000,000', '$1,300,000,000', '$1,400,000,000', '$1,400,000,000', '$1,395,000,000', '$1,200,000,000', '$1,000,000,000', '$1,000,000,000', '$842,000,000', '$887,000,000', '$860,000,000', '$825,000,000', '$799,000,000', '$757,000,000', '$751,000,000', '$701,600,000', '$660,000,000', '$600,000,000', '$577,000,000', '$559,000,000', '$540,000,000', '$532,000,000', '$518,400,000', '$500,000,000', '$500,000,000', '$437,000,000', '$400,000,000', '$350,000,000', '$300,000,000', '$277,000,000'].
In c++ A binary search member function of SortedType has the following prototype: void.SortedType::BinarySearch(int value, bool&...
In c++ A binary search member function of SortedType has the following prototype: void.SortedType::BinarySearch(int value, bool& found); Write the function definition as a recursive search, assuming an array-based implementation. Add a main function as a driver to test the BinarySearch. Test the edge cases.
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First,...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First, declare and initialize a string. You can name the variable whichever way you want and you can initialize it to whichever value you want. Then, use a for loop to print its characters; one at a time, until you reach the null character. After this, go ahead and declare a second string (since you are not initializing it right away, you will have to...
Not sure how to prompt these functions here. I am trying tocreate a holiday shopping...
Not sure how to prompt these functions here. I am trying to create a holiday shopping list. Here are my three requirements'''This function should prompt the user for the names of all the family members that they will be purchasing gifts for this holiday and return those names in a list'''def family_names():names = []return names'''This function takes the names of all family members as a list and asks the user how much money they will spend on each person. These...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i <= 0) { cout << "!"; --i; }
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure you understood the concept of “the dot” in programming. Go ahead and declare an array of characters with a default length (whichever length you want, it's fine). Next, you want to ask the user for a phrase and store the characters in your array, but before you do that, ask the user for an estimated length of the array. If the length given is...
C++. How do I reverse this encryption? Here is the question: "A company that wants to...
C++. How do I reverse this encryption? Here is the question: "A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your program should read a four-digit integer in main() entered by the user and encrypt it as follows: 1. Replace each digit with the result of adding 7 to the digit and...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100;...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100; i++) myAry = i + 2; for(int i=100; i>0; i--) cout << myAry[i] << '\t'; The first for loop assigns myAry 99 values and the null character. The second for loop prints out myAry elements backwards. The index in the second for loop is out of bounds. Only the first loop needs the null character. Q3. A value returning function that takes one parameter,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT