Sunday, June 4, 2017

Day 7

Topics

  • Music Lab
  • Random Number Programming
  • Factorial programming
Music Lab

   I made the function of the X-Files theme to be played by my speaker. It wasn't until I had already finished the damn thing that I found out I could have downloaded a library of pitch and  simply called the values I would need. Doing that probably would have made the theme more accurate than it was.  




Random Number Programming

    The first part of the homework was to write a program that simulated rolling two random dices. This allows me to call the function without having to write out each dice roll.


   The main function is this. The for loop is perfect for what I wanted to do.



Factorial progamming

   Then we were to appromiate a factorial with a function....



   The First thing I did was to define the constants needed for the functions. No sense in using memory here.


   I needed to account for the definition of factorial in the function which is why I first added a little if statement that returns 1 when the value of n is 0 or 1. Then i simply broke the function into its parts.



   I decided to test my code my using it to compute the factorial of 4.



the approximation wasn't at all that great. Even at the low number check it was off by 1. I will try higher values.



   This is not a great approximation at all. Factorial 12.




Oh well! This the program works, at least.


No comments:

Post a Comment