2. (Estimates of Pi) an Approximate Value of Pi Can Be Calculated Using the Series Given Below

2. (Estimates of Pi) an Approximate Value of Pi Can Be Calculated Using the Series Given Below

<p>CMPT 201 Fall 2017 Homework 4 Due: Friday, October 27 at 11AM</p><p>Please print your name and assignment number and submit a hardcopy (printout) of your solution. Your solution to each problem should include the C++ source code and the screenshot of the a test run. A solution without a test run will have points deducted.</p><p>1. (Characters for the ASCII Codes) Write a program that uses a for loop to display the characters for the ASCII codes 32 through 127. Display 16 characters on each line.</p><p>2. (Estimates of Pi) An approximate value of pi can be calculated using the series given below: </p><p> pi = 4 [1 – 1/3 + 1/5 – 1/7 + 1/9 ... + ((-1)n)/(2n + 1) ]</p><p>Write a program to calculate the approximate value of pi using this series. The program takes an input n that determines the number of terms in the approximation of the value of pi and outputs the approximation.</p><p>3. (Prime Numbers) Write a program that finds and prints all of the prime numbers between 3 and 100. A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, ...). One way to solve this problem is to use a doubly nested loop. The outer loop can iterate from 3 to 100 while the inner loop checks to see if the counter value for the outer loop is prime. One way to see if number n is prime is to loop from 2 to n – 1 and if any of these numbers evenly divides n, then n must be prime. (Extra credit will be given if a more efficient algorithm is developed.)</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us