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
-
You have been appointed to the board of directors for a local not- for- profit organization called Food for Friends (FFF). This organization has been in operation for 12 months and has never prepared...
-
What character string does the binary ASCII code 1010100 1101000 1101001 1110011 0100000 1101001 1110011 0100000 1000101 1000001 1010011 1011001 0100001 represent?
-
One function of the AIS is to provide adequate controls to ensure the safety of organizational assets, including data. Many people, however, often view control procedures as red tape. Discuss how...
-
The SEC attempts to protect investors who are purchasing newly issued securities by making sure that the information put out by a company and its investment bankers is correct and is not misleading....
-
Determine the implied forward zero coupon interest rate in 1 year with a tenor of 1 year based on the current Dollar interest swap rates with the following tenors: 1 year 1% 2 yeara 3 % calculate the...
-
Jerry Stevenson is the manager of a medical clinic in Scottsdale, AZ. He wants to analyze patient data to identify high-risk patients for cardiovascular diseases. From medical literature, he learned...
-
The following transactions pertain to the operations of Ewing Company for Year 1 : Acquired $ 3 0 , 0 0 0 cash from the issue of common stock. Provided $ 6 5 , 0 0 0 of services on account. Paid $ 2...
-
DECISION SCIENCE DATA ANALYSIS: INTERIM REPORT via ORAL ASSESSMENT (Please refer to the guideline for your group project "Data Analysis Project Report") Assessment of this report is via ORAL...
-
(a) 35+12i The polar form is Give an exact answer.
-
Make up an outline for French cultural rules and gift giving for a presentation, write it in english. It must be Use a 12-pt font size. Double-spacing. . Write your outline using a writing style that...
-
Differentiate f(x) = ax5-4ax with respect to x. Assume that a is a constant.
-
Vision and Wanda own a new airline that has had one stock issue in which it sold 500,000 shares to the public at $12 per share. Using the table below, what is the value of the company's retained...
-
First construct the frequency distribution. Class Frequency, f 0-4 5-9 10-14 15-19 20-24 25-29 30+ Find an approximation for the sample mean. x= (Type an integer or decimal rounded to the nearest...
-
On average there are four traffic accidents in a city during one hour of rush-hour traffic. Use the Poisson distribution to calculate the probability that in one such hour there arc (a) No accidents...
-
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.
-
When should a board consider forming a governance, development, audit, membership, and compensation committee? Or should any of these be task forces?
-
What might be the challenges of a board member serving on an organizational committee?
-
What are some potential roles for advisory councils? How can organizations use these groups effectively?
Study smarter with the SolutionInn App