This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:acrowle1:portfolio:cprogproject3 [2014/03/02 22:20] – [References] acrowle1 | user:acrowle1:portfolio:cprogproject3 [2014/03/09 14:53] (current) – [Project: dayofweek] acrowle1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Project: | + | ======Project: |
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 **// | 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 **// | ||
- | Example 1: | + | Example 1 (My first submitted program): |
Line 94: | Line 94: | ||
After more consideration, | After more consideration, | ||
- | 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, | Second mistake: The way I used the curly braces. Essentially, | ||
- | 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 | + | 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. |