Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please program in C++ 1. Write a program that consists of a while loop that each time around the loop reads in two ints and

Please program in C++

1. Write a program that consists of a while loop that each time around the loop reads in two ints and the prints them.

2. Write a program that consists of a while loop that each time around the loop reads in a double and keeps track of the sum. Then print the value of sum.

3. Write a program that consists of a while loop that each time around the loop reads in a double and keeps track of the min value. Then print the value of the min.

4. Write a program that consists of a while loop that grows a vector v of doubles. Then use a for loop to compute the average value.

5. Write a function that computes the reciprocal of factorial. The factorial of a nonnegative integer is defined as n! = 1 2 n with 0! = 1.

6. For each sum, write a function to compute and return the value of the sum. Assume that the value of n is an argument of the function.

s = 1 + 3 + 5 + . . . + (2n ? 1)

s = 1 + 1 2 + 1 3 + . . . 1/n

s = 1 ? 1 2 + 1 3 ? 1 4 + . . . 1/n

s = x ? x 3 3! + x 5 5! ? x 7 7! + . . . x^2n?1/(2n ? 1)! .

7. Write a function that computes the number of digits of an integer. For example if n = ?43 the function returns value 2. You should do this by counting the number of times n needs to be divided by 10 until n reaches 0.

8. Write a code that computes the values ek = (1 + 1/k)^k . The loop should finish when |ek+1 ? ek| < (10)^?5 . The number e is also the limit of the following series.

9. Write a code that computes the values en = 1 0! + 1 1! + 1 2! + . . . 1 n! where n must be an integer that is at least zero.

10. Write a code that computes the following sums (Gregory and Lebiniz formula for computing ?) p = 4 ? 4/3 + 4/5 ? 4/7 + . . . 4/n

11. Identify and correct the errors in each of the following statements:

// the code below should print the integers from 1 to 10

x = 1;

while ( x <= 10 );

++x;

// the code below should print the value 1 to 10

n = 1;

while ( n < 10 )

cout << n++ << endl;

// the code below should print numbers from 100 down to 1

For ( x=100, x >= 1, ++x )

cout << x << endl;

// the code below should print odd values from 19 to 1

for ( x = 19; x >= 1; x += 2 )

cout << x << endl; // the code below should print even integers from 2 to 100

counter = 2;

do

{

cout << counter << endl;

counter += 2;

} While ( counter < 100 );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago