Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.03 KB

hw1probs.md

File metadata and controls

31 lines (20 loc) · 1.03 KB

Homework problems level 1

Basic Math

Loops

  1. Write a loop to sum the integers from 1 to 100
  2. Write a loop to sum the even numbers from 1 to 50.
  3. Write a loop to sum the odd numbers from 1 to 50.
  4. 3n+1 conjecture. Read in a positive integer from the keyboard and repeatedly apply the following rule: If the number is odd, multiply by 3 and add 1 If the number is even, divide by 2 Repeat until the number 1 is reached. For example n = 5 5 16 8 4 2 1 n = 30 15 46 23 40 20 10 5 16 8 4 2 1

Floating Point

  1. Write a loop to compute the floating point sum from 1/1 + 1/2 + ... + 1/n, for n=100

Compute the same sum backwards. Print out the difference between the two sums and determine which one is more accurate.

  1. Mystery Sum: Compute the sum: $1/1^2 + 1/2^2 + 1/3^2 + ... 1/n^2$.

Nested Loops

  1. Read in a positive integer from the keyboard and print out an n by n multiplication table
  2. Read in a positive integer n and find the longest 3n+1 conjecture for every number from 1 up to n.