EE106 - iteration problems PDF

Title EE106 - iteration problems
Author James Smythe
Course Engineering Design For Software Development 1
Institution University of Strathclyde
Pages 1
File Size 36.8 KB
File Type PDF
Total Downloads 73
Total Views 140

Summary

iteration problems...


Description

55

4.7. PROBLEM SETS

4.7

Problem Sets

Computer programming requires a range of skills: knowledge of the syntax of a particular language, an understanding of data types and algorithms, the ability to test and debug code, experience in structuring code appropriately, and the ability to translate concepts from the physical world into a working application. The translation of real world problems into working code is perhaps the most creative and frustrating aspect of programming. The problems below are designed to encourage this creativity, and highlight the advantage of having a notepad and pen ready when writing code.

1. Use a for loop to print the numbers 1, 2, 3, ..., 9, 10 to the screen. 2. Modify the first exercise to print the numbers 2, 4, 6, 8, 10 to the screen. 3. Look up the phrase “Taylor Series” in Wikipedia, there should be several expansions for well-known mathematical identities. With reference to equations 4.4, write some code to calculate the hyperbolic cosine (cosh) of a floating point number entered from the keyboard, your code should consider the first 50 terms. Before you begin, carefully consider whether a for loop or while loop is more appropriate. The objectives of this exercise are to gain experience (i) writing a nested loop, and (ii) to experiment with different step sizes. Hints: work on the inner loop first to ensure it operates as you expect; use print() statements during the writing and testing phase within the body of the loop. cosh x =

x4 x6 x0 x2 + + + +··· 0! 2! 4! 6!

(4.4)

4. Look up the phrase “Fibonacci Number” in Wikipedia. This should describe a sequence of numbers: 0, 1, 1, 2, 3, 5, ... Translate this description into working code that prints the first 10 numbers of the sequence. The objective of this exercise is to demonstrate the necessary thought process required to initialise variables appropriately before entering a loop. Your code should contain a singe for loop and a single print() statement....


Similar Free PDFs