CSC231 Homework 5 2012

From dftwiki3
Revision as of 08:42, 3 October 2012 by Thiebaut (talk | contribs) (Grading)
Jump to: navigation, search

--D. Thiebaut 09:40, 3 October 2012 (EDT)


Page under construction!
UnderConstruction.jpg

Problem #1

Assume that we want to print the first 60 terms of the series of Homework 4 using a Java program. We are aware of limitations due to the range of integers, so we use the long data type to represent the terms of the series.

Here's our first shot at this program (sorry, undocumented... just a first rough version ;-):

// Hw5a.java
// Prints first terms of recursive series:
// F[1] = 1, F[2] = 1, F[n] = 2 * F[n-1] + F[n-2] - 1
// Stops when negative value comes up...
// To compile and run:
//    javac Hw5a.java
//    ./Hw5a
//
class Hw5a {
    public static void main(String[] args ) {
	long Fn, Fn_1, Fn_2;
	int count;
	Fn_1 = 1;
	Fn_2 = 1;
	System.out.println( "F[1] = 1" );
	System.out.println( "F[2] = 1" );

	count = 2;
	while ( true ) {
	    Fn = 2 * Fn_1 + Fn_2 - 1;
	    Fn_2 = Fn_1;
	    Fn_1 = Fn;
	    System.out.println( "F[" + count + "] = " + Fn );
	    count++;
	    if ( Fn <= 0 )
		break;
	}
    }

}

You can create this program and run it. You will observe that its last output is:

   F[53] = -6917272433323338267


Your Assignment

  • Find a way to generate the exact, unsigned values in decimal of the last 7 terms of the series of 60 terms. In other words find a way to generate the exact unsigned values of F[53] to F[60].
  • Your answer should give these values, and explain how you obtained them.

Grading

  • Extra credits if your answer is a program written in a non interpreted language...
  • Lower credits (up to B only) for solutions done by hand... (After all, we are programmers, and we don't want to do work a computer can do for us!)

Submission

  • Write your answer as raw text in a file called hw5a.txt and submit it as follows:
  rsubmit hw5 hw5a.txt
  • The text file should contain the correct F[53] to F[60] terms and your explanations.