User Tools

Site Tools


user:acrowle1:portfolio:cprogproject3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
user:acrowle1:portfolio:cprogproject3 [2014/03/02 22:19] – [References] acrowle1user:acrowle1:portfolio:cprogproject3 [2014/03/09 14:53] (current) – [Project: dayofweek] acrowle1
Line 1: Line 1:
-======Project: squares======+======Project: Squares======
  
 A project for CSCS1320S14 by Alana Whittier during the Spring Semester 2014. A project for CSCS1320S14 by Alana Whittier during the Spring Semester 2014.
Line 50: Line 50:
 My first attempt at writing the program was using the modulus operator, %, although abandoned that effort quickly as it was not clear what to do with the factor in order to implement the mental math technique. I then decided to implement the computation of the square in what I deemed more simplistic of an approach and then used a series of if, else if statements to output **//only//** the values I wanted the user to input and obtain (two-digit integers ending in 5), and  finally an else statement in which "Error: Invalid Entry" is displayed for all values greater than 95 and for all values that do not end in 5.  My first attempt at writing the program was using the modulus operator, %, although abandoned that effort quickly as it was not clear what to do with the factor in order to implement the mental math technique. I then decided to implement the computation of the square in what I deemed more simplistic of an approach and then used a series of if, else if statements to output **//only//** the values I wanted the user to input and obtain (two-digit integers ending in 5), and  finally an else statement in which "Error: Invalid Entry" is displayed for all values greater than 95 and for all values that do not end in 5. 
  
-Example 1: +Example 1 (My first submitted program)
  
  
Line 94: Line 94:
 After more consideration, I decided to try again writing the program using the modulus operator, which I called R and the factor which I declared a variable. This code is substantially more efficient as it does not require so many lines of code to obtain the squared values. However, I am uncertain how to completely limit the computation and output, since this approach also works for 3 and 4 digit integers ending in five.  After more consideration, I decided to try again writing the program using the modulus operator, which I called R and the factor which I declared a variable. This code is substantially more efficient as it does not require so many lines of code to obtain the squared values. However, I am uncertain how to completely limit the computation and output, since this approach also works for 3 and 4 digit integers ending in five. 
  
-See the code below.+Example 2 (The second program using modulus operator and factor): 
  
  
Line 211: Line 211:
 Second mistake: The way I used the curly braces. Essentially, I was embedding several else if statements within the initial if. By correcting this my code worked flawlessly. Second mistake: The way I used the curly braces. Essentially, I was embedding several else if statements within the initial if. By correcting this my code worked flawlessly.
  
-Since my initial attempt at writing this program included the modulus operator, which had been quickly abandoned, I decided to revisit that since I now had a working program written in a manner I felt was more simplistic. What I realized that I was missing from my initial program was the factor (the number of times that 10 went into the integer). For example, if I declared the factor to be i/10 and R= i%10, then for an integer value of 25, R=5 and the factor=2, since 10 can go into 25 twice, with a remainder of 5. With this program written this way, the same mental math technique works for 3 and 4 digit integers ending in 5 as well, to compute the squares. This code is shown above as the second method in the Procedure section.    +Since my initial attempt at writing this program included the modulus operator, which had been quickly abandoned, I decided to revisit that since I now had a working program written in a manner I felt was more simplistic. What I realized that I was missing from my initial program was the factor (the number of times that 10 went into the integer). For example, if I declared the factor to be i/10 and R= i%10, then for an integer value of 25, R=5 and the factor=2, since 10 can go into 25 twice, with a remainder of 5. With this program written this way, the same mental math technique works for 3 and 4 digit integers ending in 5 as well, to compute the squares. This code is shown above in Example 2 of the Procedure section.    
  
  
Line 227: Line 227:
 In performing this project, the following resources were referenced: In performing this project, the following resources were referenced:
  
 +  * http://wildaboutmath.com/2007/11/11/impress-your-friends-with-mental-math-tricks/comment-page-6/
 +  * http://saurabhg.hubpages.com/hub/Vedic-Mathematics---Quick-multiplication-techniques---Part-1
 +  * Kernighan, Ritchie //The C Programming Language// Second Edition, AT&T Bell Laboratories, 1988. Print.
 +  * email consultations and guidance from Matt Haas
user/acrowle1/portfolio/cprogproject3.1393798774.txt.gz · Last modified: 2014/03/02 22:19 by acrowle1