#include <iostream>
#include <array>
using namespace std;
int specific_pattern(short pattern[], int size) {
int pattern_found = -1;
for (int i = 0; i < size; i++) {
for (int j = i; j < size; j++)
{
if ((pattern[j]
- pattern[i]) == 20) {
for (int k = j; k < size; k++) {
if ((pattern[k] - pattern[j])
== 20) {
return
i;
}
}
}
}
}
return pattern_found;
}
int main() {
short data[] = { 10,20,31,40,55,60,65525 };
cout << specific_pattern(data, (sizeof(data) /
sizeof(data[0]))) << endl;
return 0;
}
My code from Problem 3 is printed above in bold. I need help
understanding this problem. In C++ please.

This is modification in problem 3 as 1-1-0 Detection.
#include <bits/stdc++.h>
#include <array>
using namespace std;
int specific_pattern(short pattern[], int size) {
int pattern_found = -1,flag=0,i;
for ( i = 0; i < size; i++) {
if ((pattern[i+1] - pattern[i]) == 20) {
for (int k = i+2; k < size; k++) {
if ((pattern[k] - pattern[i]) == 40) {
flag=1;
}
}
}
}
if(flag==0)
{
return i;
}
return pattern_found;
}
int main() {
short data[] = { 20,40,31,40,55,60,6525 };
cout << specific_pattern(data, (sizeof(data) /
sizeof(data[0]))) << endl;
return 0;
}
#include <iostream> #include <array> using namespace std; int specific_pattern(short pattern[], int size) { int pattern_found =...
One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << ; cout << endl; return 0; }
// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...
#include <iostream> using namespace std; template <typename Item> class MyArray{ private: Item *myarray; int size; int used; void doubleSize(); public: MyArray(); ~MyArray(); int length(); void insertHead(Item i); void insertTail(Item i); void deleteHead(); void deleteTail(); void sortAscending(); void sortDescending(); Item operator [](int i){ return myarray[i]; } }; template <typename Item> MyArray<Item>::MyArray(){ size = 5; used = 0; myarray = new Item[size];...
#include<iostream> #include<cstdlib> using namespace std; int main() { // create array of size 20 int arr[20]; int i; cout<<"scores : "; for( i = 0 ; i < 20 ; i++ ) { // generate a random number i range 70 - 100 an add it to arr arr[i] = rand() % 31 + 70; cout<<arr[i]<<" "; } // store the total score int total = 0;...
#include <iostream>
using namespace std;
int * newZeroArray(int size) {
//your code here
}
int main() {
int size = 10;
int * A = newZeroArray(size);
for(int i = 0; i < size; i++)
cout << A[i] << " ";
cout << endl;
}Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...
Example program
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> factor(int n)
{
vector <int> v1;
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
v1.push_back(2);
}
// n must be odd at this point. So we can
skip
// one element (Note i = i +2)
for (int i = 3; i <=...
In C++
#include<iostream>
using namespace std;
//Implement the function below.
bool is_fibonacci_array(int*,int);
//Param 1: pointer to the beginning of an array of integers
//Param 2: size of that array
//Returns: true, is every element in the input array is a Fibonacci number
//(the order of the numbers in the array need not be ordered
//as per the Fibonacci sequence)
//false, otherwise
//A Fibonacci sequence is generated as follows.
//The first two numbers in the sequence are 0 and 1.
//The...
a7q3.cc File
#include <iostream>
#include <cstring>
#include "ArrayList.h"
using namespace std;
// Algorithm copy(s)
// Pre: s :: refToChar
// Post: memory allocated on heap to store a copy
// Return: reference to new string
char *copy(char *s) {
char *temp = new char[strlen(s)+1];
strcpy(temp,s);
return temp;
}
void test_ListOperations(){
cout << "testing createList" << endl;
List *myList = createList(10);
if (myList == NULL){
cout << "createList failed" << endl;
return;
} else{
cout << "createList succeeded"...
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...