Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

For Loops

For each of the programs assigned below, submit the following:

  • Hard copy of the source code.
  • Hard copy of sample executions (black or, preferably, white screen). 

Copy of the source code (.c ) saved as an electronic attachment to C Assignment 7 located in Oncourse under Assignments. 

Observe the usual guidelines regarding the initial comment section, indenting, and so on.  In addition,

  • In if-else statements, indent statements to be executed for if or else condition three spaces.  Align else or else if with corresponding if.
  • Indent statements within loops.  Indent nested loops.

 

1.   Write a program to find the approximation of ln(2) using the following formula for m+1 terms:

                            where n = 0, 1, 2, ... m

Prompt the user to enter the number of terms (between 10 and 50 inclusive) to be used in the approximation.  Use a while validation loop to assure that the number of terms is in the proper range.  Use a for loop to calculate each term in the sum and while doing so, to print a table.  Each line of the table should include the term (value of n) number, the value of the term added to the sum at that iteration accurate to 5 decimal digits, and the value of the sum at that iteration also printed with 5 decimal digits.  If there are 20 terms, they will be numbered 0 through 19.  Use doubles for the term and sum approximation values.  At the end of the program print the final value of the sum and also the actual value of ln(2) from the C library using 5 decimal digits.

2.  Write a program to calculate the factorial of a number.  The factorial n! of a positive number (integer) is defined by n! = n*(n-1)*(n-2)*...*3*2*1, where 0! = 1.

In function main prompt the user for a non-negative integer less than 20 for which the factorial is to be found.  Use a while validation loop to assure the number entered is in the proper range.  Then call a function to calculate the factorial.  The input to the function is the integer n and the return value is n factorial.  Use data type double for the factorial.  In the function use a for loop to calculate the factorial.  Make provision for the situation in which n = 0.  Return the value of n factorial to function main and print.  Test with n = 14. 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91522662

Have any Question?


Related Questions in Computer Engineering

You are given a test to enter graduate school you must

You are given a test to enter graduate school. You must select 10 of the 13 essay questions to answer to determine your writing skills. How many ways can you select those questions?

Question suppose that someone tells you that an attribute

Question : Suppose that someone tells you that an attribute that is part of a composite primary key is also a candidate key. How would you respond to that statement? Explain.

Suppose there are three decks of cards on the table a

Suppose there are three decks of cards on the table, a number is written on each card. And each deck is sorted in decreasing order (The maximum value is on the deck in top). The goal is to find the minimum value between ...

In powerpoint what is beneficial about the usage or video

In Powerpoint, what is beneficial about the usage or Video, Audio, Animation, and Photos with Effects during presentation and work. What are some useful tools you found that would improve performance?

Question suppose two matlab functions find-nonzero and

Question : Suppose, two Matlab functions find-nonzero and row-echelon are available to use. The first function takes a vector as input and returns the location of the first nonzero entry of the input vector. The second f ...

Question suppose that an attack would do 200000 in damage

Question : Suppose that an attack would do $200,000 in damage and has a 25% annual probability of success. Spending $15,000 per year on Countermeasure A would reduce the damage of a successful attack by 50%. a) Do a risk ...

A group of adult males has foot lengths with a mean of 2693

A group of adult males has foot lengths with a mean of 26.93 cm and a standard deviation of 1.12 cm. Use the range rule of thumb to identify the limits separating values that are significantly low or significantly high. ...

What conclusions can you draw about the heat of solution

What conclusions can you draw about the heat of solution for the three salts tested and the effect on the temperature changes when the salts were dissolved in water? Your answer should include the words Endothermic and E ...

Case studyjulian lim purchased a put option at the cost of

Case study: Julian Lim purchased a put option at the cost of $0.30 each. The put option has a strike price of S$3.00 and the underlying stock is currently trading at S$3.50. Julian Lim bought 100 shares. Question: Determ ...

Question need two different postsresponses with 200 words

Question: Need two different posts(responses) with 200 words each on the below topic. 1. Develop a product service idea. A. Describe the product/service including the benefits of using the product/service B. Discuss the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As