Write a program that first get the value of a positive integer N (where N> 0)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that first get the value of a positive integer N (where N> 0) from the user. It then computes the double number 2 using the following series. Use a looping structure. All divisions are real, floating point divisions. Z=1+(1/2) + (1/3) + (1/4)+...+(1/N) Sample Session Microsoft Visual Studio Debug Console Enter a positive integer: 10 - 2.92897 Problem 2: Write a program that asks the user to input a positive integer x. The program then computes and displays the value. of the floating point number 2 using the following formula: (All divisions should be real, floating point divisions). Use afor looping structure. 2 = Microsoft Visual Studio Debug Console Enter a positive integer: 2 Z 3.53804 1 1 x x+1 x+2 Note that the program should NOT allow the user to input a value <=0 Sample Session 1: Sample Session 2: GN Microsoft Visual Studio Debug Console Enter a positive integer: -2 Invalid input ++ 1 x + 50 GS Microsoft Visual Studio Debug Console Enter two integers: 3 7 Sum 25 Problem 3: Write a program that asks the user to enter the valuesfor two positive integers Nl and N2. It is assumed that user will enter those values such that N2 is always greater than NI. The program then computes and prints the sum of all the integers present between NI and N2 (with both NI and N2 included). Your program must use a forlooping structure For example, if N1-3 and N2-7, then the sum printed will be 25 (ie, -3+4+5+6+7). Sample Session 1: Problem 4: Write a program that generates a table showing the angle 8 (in radians), from 0 to 2m in the step of 1/4, and the corresponding values for sin(8) and cos). Moreover, prove the identity that sin²(8) + cos²(8) 1 for each value of 8. Hint: Declare and initialize as const double PI- 3.14159; Use a for loop with theta (angle) varying from 0 to 2*, with end of iteration expression incrementing theta by/4. Use sin(theta) and costheta) functions from <math> library to get the values of sin(theta) and costheta), respectively. The angle theta should be in radians. Use cout.precision (5); cout <<scientific; before printing the numbers to form at the output as shown in the sample. Sample Output: (Your output may not be perfectly aligned within columns) EA Microsoft Visual Studio Debug Console sin(theta) theta 0.000000+00 7.85397e-01 0.000000+00 7.071060-01 1.570790+00 1.000000+00 2.35619e+00 7.071080-01 3.141590+00 2.653590-06 3.926990+00 4.712390+00 5.49778e+00 6.283180+00 cos(theta) 1.000000+00 7.07107e-01 1.32679e-06 -7.071050-01 -1.000000+00 -7.071040-01 -7.071090-01 -1.000000+00 -3.980380-06 -7.071100-01 7.071030-01 -5.307180-06 1.000000+00 sin2(theta) + cos2(theta) 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 A Write a program that first get the value of a positive integer N (where N> 0) from the user. It then computes the double number 2 using the following series. Use a looping structure. All divisions are real, floating point divisions. Z=1+(1/2) + (1/3) + (1/4)+...+(1/N) Sample Session Microsoft Visual Studio Debug Console Enter a positive integer: 10 - 2.92897 Problem 2: Write a program that asks the user to input a positive integer x. The program then computes and displays the value. of the floating point number 2 using the following formula: (All divisions should be real, floating point divisions). Use afor looping structure. 2 = Microsoft Visual Studio Debug Console Enter a positive integer: 2 Z 3.53804 1 1 x x+1 x+2 Note that the program should NOT allow the user to input a value <=0 Sample Session 1: Sample Session 2: GN Microsoft Visual Studio Debug Console Enter a positive integer: -2 Invalid input ++ 1 x + 50 GS Microsoft Visual Studio Debug Console Enter two integers: 3 7 Sum 25 Problem 3: Write a program that asks the user to enter the valuesfor two positive integers Nl and N2. It is assumed that user will enter those values such that N2 is always greater than NI. The program then computes and prints the sum of all the integers present between NI and N2 (with both NI and N2 included). Your program must use a forlooping structure For example, if N1-3 and N2-7, then the sum printed will be 25 (ie, -3+4+5+6+7). Sample Session 1: Problem 4: Write a program that generates a table showing the angle 8 (in radians), from 0 to 2m in the step of 1/4, and the corresponding values for sin(8) and cos). Moreover, prove the identity that sin²(8) + cos²(8) 1 for each value of 8. Hint: Declare and initialize as const double PI- 3.14159; Use a for loop with theta (angle) varying from 0 to 2*, with end of iteration expression incrementing theta by/4. Use sin(theta) and costheta) functions from <math> library to get the values of sin(theta) and costheta), respectively. The angle theta should be in radians. Use cout.precision (5); cout <<scientific; before printing the numbers to form at the output as shown in the sample. Sample Output: (Your output may not be perfectly aligned within columns) EA Microsoft Visual Studio Debug Console sin(theta) theta 0.000000+00 7.85397e-01 0.000000+00 7.071060-01 1.570790+00 1.000000+00 2.35619e+00 7.071080-01 3.141590+00 2.653590-06 3.926990+00 4.712390+00 5.49778e+00 6.283180+00 cos(theta) 1.000000+00 7.07107e-01 1.32679e-06 -7.071050-01 -1.000000+00 -7.071040-01 -7.071090-01 -1.000000+00 -3.980380-06 -7.071100-01 7.071030-01 -5.307180-06 1.000000+00 sin2(theta) + cos2(theta) 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 1.000000+00 A
Expert Answer:
Answer rating: 100% (QA)
Problem 1 As per the Question i used looping structures to complete i have wrote this problem in pyt... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Discuss the strategies for scaling databases to handle large volumes of data and high transaction rates. Explain the concepts of sharding, replication, and clustering. Describe how databases achieve...
-
Imagine that Costco has $500,000 of sales (selling 31,250 units) in August and has a contribution margin ratio of 40% and fixed costs of $20,000. If sales in units increase by 15% in September, what...
-
Ivanhoe Company incurred research and development costs of $ 9 0 0 0 0 to develop a patent, and legal fees of $ 3 0 0 0 0 to register the patent. The patent has a legal life of 2 0 years and a useful...
-
XYZ purchased an equipment worth of $150,000 including insurance cost $30,000 and duty cost $20,000 on May 15, 2018. They have decided to capitalize the $35,000 installation charge instead of $20,000...
-
Why can't car dealerships simply keep paying based on past systems?
-
At what stage in U.S. trade history did protectionism reach its high point?
-
Saturn Corporation issued \(\$ 400,000\) of \(6 \%\) bonds payable on June 30. The bonds were dated April 30, and the semiannual interest dates are April 30 and October 31. 1. How much cash will...
-
Prepare the journal entries that the lessee should make to record the following transactions. 1. The lessee makes a lease payment of $80,000 to the less or in an operating lease transaction. 2....
-
Since McDonald\'s entered the coffee market, it has heavily advertised to gain customer awareness and interest. To retain loyalty, they have used a \"buy 7 get 8 th \" free program. What is this an...
-
A residential project has the following information: Four major activities are scheduled across a 4-month time span (shown in the below bar chart). Assuming the monthly indirect cost (i.e., site...
-
The interest rate for the first five years of a $29,000 mortgage loan was 3.45% compounded semiannually. The monthly payments computed for a 10-year amortization were rounded to the next higher $10....
-
You have just finished reading an article in a personnel journal about compensation plans. The turnover rate in your company is too high, considering the cost of losing experienced employees. The CEO...
-
In response to intense foreign competition, Florex Company has taken steps to improve the quality of its products. A summary of its quality costs (in thousands) over the past two years is given...
-
Republic Services (RS) Submit high bid Submit low bid RS: $1.7 billion RS: $2.1 billion WM: $2.5 billion WM: $1.2 billion Submit low bid RS: $0.3 billion RS: $0.4 billion WM: $3.7 billion WM: $1.7...
-
Mark Twain popularized the phrase "There are three kinds of lies: lies, damned lies, and statistics." How do people manipulate data and statistics to deceive? Give two examples. Provide at least...
-
Given the following free cash flows. determine the IRR for the three independent projects A, B, and C. Data Table Initial outlay (Click on the following icon in order to copy its contents into a...
-
A cylindrical vessel containing a liquid is closed by a smooth piston of mass m as shown in the figure. The area of cross section of the piston is A. If the atmospheric pressure is Po, find the...
-
State whether each of the following will increase or decrease the power of a one-way between-subjects ANOVA. (a) The effect size increases. (b) Mean square error decreases. (c) Mean square between...
-
Consider a class Time that represents a time of day. It has attributes for the hour and minute. The hour value ranges from 0 to 23, where the range 0 to 11 represents a time before noon. The minute...
-
ELIZA was a program written in 1966 that parodied a psychotherapist session. The user typed sentences and the program used those words to compose a question. Create a simple GUI application based on...
-
Revise the method selectionSort that appears in Listing 7.10 so that it calls the method described in the previous exercise. Listing 7.10 /** Class for sorting an array of base type int from smallest...
-
The gross profit ratio is equal to: (a) profit divided by net sales. (b) cost of sales divided by net sales. (c) net sales minus cost of sales, divided by net sales. (d) net sales minus cost of...
-
What inventory cost flow method does Dominos Pizza Enterprises Ltd use for its inventories?
-
Which inventory cost flow method produces the highest profit in a period of rising prices?
Study smarter with the SolutionInn App