Write output of following piece of code a) #include #include using namespace std; string arith_geo_sequence(int nums[],...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write output of following piece of code a) #include <iostream> #include <string> using namespace std; string arith_geo_sequence(int nums[], const int size) { int diff_arith = 0, diff_geo = 0; bool arith_flag = true, geo_flag = true; diff_arith = nums[1] - nums[0]; diff_geo = nums[1] / nums[0]; for (int y = 0; y < size-1 && arith_flag; y++) PUR { arith_flag false; if (nums[y] + diff_arith = nums[y + 1]) { arith_flag = true3; } } for (int z = 0; z < size - 1 && geo_flag; z++) { geo_flag = false; if (nums[z] * diff_geo == nums[z + 1]) { geo_flag = true; } TECHNO if (arith_flag) { return "Arithmetic sequence"; else if (geo_flag) { return "Geometric sequence"; } else { return "Not Arithmetic/Geometric sequence"; } } SCIENCE int main() { OF int nums1[] = { 1, 3, 5, 7 }; int nums2[] = { 2, 4, 8, 16, 32 }; int nums3[] = { 1, 2, 3, 4, 5, 6, 8 }; %3D int nums4[] = { 3, 6, 9, 12 }; cout << arith_geo_sequence(nums1, sizeof(nums1) / sizeof(nums1[0])) << endl; cout << arith_geo_sequence(nums2, sizeof(nums2) / sizeof(nums2[0])) << endl; cout << arith_geo_sequence(nums3, sizeof(nums3) / sizeof(nums3[0])) << endl; cout << arith_geo_sequence(nums4, sizeof(nums4) / sizeof(nums4[0])) << endl; return 0; } Write output of following piece of code a) #include <iostream> #include <string> using namespace std; string arith_geo_sequence(int nums[], const int size) { int diff_arith = 0, diff_geo = 0; bool arith_flag = true, geo_flag = true; diff_arith = nums[1] - nums[0]; diff_geo = nums[1] / nums[0]; for (int y = 0; y < size-1 && arith_flag; y++) PUR { arith_flag false; if (nums[y] + diff_arith = nums[y + 1]) { arith_flag = true3; } } for (int z = 0; z < size - 1 && geo_flag; z++) { geo_flag = false; if (nums[z] * diff_geo == nums[z + 1]) { geo_flag = true; } TECHNO if (arith_flag) { return "Arithmetic sequence"; else if (geo_flag) { return "Geometric sequence"; } else { return "Not Arithmetic/Geometric sequence"; } } SCIENCE int main() { OF int nums1[] = { 1, 3, 5, 7 }; int nums2[] = { 2, 4, 8, 16, 32 }; int nums3[] = { 1, 2, 3, 4, 5, 6, 8 }; %3D int nums4[] = { 3, 6, 9, 12 }; cout << arith_geo_sequence(nums1, sizeof(nums1) / sizeof(nums1[0])) << endl; cout << arith_geo_sequence(nums2, sizeof(nums2) / sizeof(nums2[0])) << endl; cout << arith_geo_sequence(nums3, sizeof(nums3) / sizeof(nums3[0])) << endl; cout << arith_geo_sequence(nums4, sizeof(nums4) / sizeof(nums4[0])) << endl; return 0; }
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write output of following program. #include using namespace std; void repchar(char, int); int main() { repchar(-, 43); cout << Data type Range << endl; repchar(=, 23); cout << char...
-
True / False Questions If true, explain. Iffalse, give a 2 ( 2 counterexample. (a) A diagonal matrix is invertible if and only if its diagonal elements are nonzero. True or false? (b) An upper...
-
True / False Questions: If false, give a counterexample or a brief explanation? (a) A solution set of a homogeneous system of linear algebraic equations, given by Is a subspace of R4. True or false?...
-
The data below are the calories and grams of sugar in some popular store bought cookies. Calories 143 Grams of Sugar 12 97 9 200 11 149 19 84 4 57 9 198 21
-
At the end of 2016, Richards Company prepared a trial balance, recorded and posted its adjusting entries, and then prepared an adjusted trial balance. Selected accounts and account balances from the...
-
Two very long (in the direction normal to the page) bars having the prescribed initial temperature distributions are to be soldered together. At time t = 0, the m = 3 face of the copper (pure) bar...
-
Basis of differentiation is part of the Barringer/Ireland Business Model Template. We define this term in this chapter as what causes consumers to pick one companys products over anothers. What is...
-
Millennial Technologies, a designer, manufacturer, and marketer of PC cards for portable computers, printers, telecommunications equipment, and equipment diagnostic systems, was the darling of Wall...
-
4.Indicate, by clicking on the relevant boxes, whether the following statements are true or false in relation to business valuation. The earnings yield method and the dividend growth model should...
-
Eta Corporation approaches Lily White, the CEO and sole shareholder of MuCo, regarding the acquisition of MuCo's cat toy division assets (worth $1.3 million). As selling the assets would create a...
-
3. Determine symmetry species for the SALCS required for the formation of Br - Fo bonds by the 5 F atoms in BrFs (C).
-
A small pool of fire burns at the rate of 293g/m min with a diameter of 5.8m and heat of combustion of the fuel is 3221kJ/g. Determine the heat release rate. Round answer to 2 decimal places and...
-
Explains the accounting method's effect on specific financial statements clearly and with sufficient detail to demonstrate why the company chose it. Compare how two accounting methods differ in their...
-
What does keeney o brien recommends to manage the time and responsibilities effectively ?
-
How do you promoting the free exercise of speech and religion and resisting the forces of totalitarianism that seek to crush dissenting opinions and beliefs.
-
For the following program: Execute the program by single steps. For each step write vales of registers IP, AX, CX, SI, DI, and Flag. MOV CX,0200H MOV AX, OD2A4 H XCHG AX, CX MOV SI,100H MOV DI,120H...
-
A brief description of the Northern Forests in Wisconsin A brief explanation of Natural Capital and Natural Income The ecosystem of Northern Forests; goods and services, with explanations/specifics...
-
DEPARTMENT DATA EMPLOYEE DATA EmployeeNumber FirstName Mary Rosalie Richard George Alan 3 4 5 7 8 9 855555ES 12 13 14 15 16 17 Create the database tables in SQL or ACCESS: 18 19 20 PROJECT DATA Ken...
-
a) List the four steps in business process analysis? b) Explain why each is important?
-
a) How are linking attributes used to connect disparate databases? b) Explain information triangulation? c) What are the odds of correctly identifying a person based on their ZIP code, date of birth,...
-
(a) Give two situations in which the risk of deception is high. (b) Give two situations in which the risk of deception is low.
-
Who was Phar-Mors flamboyant Chief Executive Officer?
-
Which of the following generally is not considered something of value? 1. Cash, money or checks 2. Airline miles or hotel credits associated with frequent activity (e.g., frequent flier miles) 3. An...
-
Which of the following is not one of the five major categories of fraudulent disbursements? 1. Payroll schemes 2. Expense reimbursement schemes 3. Shell company schemes 4. Billing schemes
Study smarter with the SolutionInn App