ECS 30A

Homework #8 (Part A)

Fall 2008


Due: December 3. 

Written: 4:00pm in 2131 Kemper. 

Programs: 11:59pm using handin to cs30a p7 directory.

Filenames: fast_fib.c, find_digits.c, palindrome.c

 

Written:  Problems #4 and #5 on page 546

                                                          

Programming. All programs should be able to compile with no warnings when compiled with the –Wall option.  You should put your name(s) in a comment on the first line of each file.  The prompts, and output format of each program must match the examples exactly. 

 

(1)  Programming problem #2 on page  521. Filename: fast_fib.c

       Note: the function fast_fib must make only one recursive call.

 

[…@pc…]$ fast_fib.out

Enter the positive integer n > 1

The 1-th and 2-th Fibonacci numbers are 1 and 1.

[…@pc…]$ fast_fib.out

Enter the positive integer n > 2

The 2-th and 3-th Fibonacci numbers are 1 and 2.

[…@pc…]$ fast_fib.out

Enter the positive integer n > 3

The 3-th and 4-th Fibonacci numbers are 2 and 3.

[…@pc…]$ fast_fib.out

Enter the positive integer n > 9

The 9-th and 10-th Fibonacci numbers are 34 and 55.

 

 (2) Programming problem 1 on page 528. Filename: find_digits.c

         

[…@pc…]$ find_digits.out

  Enter a line of characters > ISBN 0-321-40991-4

The digits are 0321409914

[…@pc…]$ find_digits.out

  Enter a line of characters > SFO2009sabJ15

  The digits are 200915

 

(3) Programming problem 2 on page 548. Filename: palindrome.c

 

[…@pc…]$ palindrome.out

This program will test to see if a string is palindrome.

Input a deblanked, unpunctated string of charaters.

Enter exit to stop

Input: hannah

hannah is a palindrome.

Input: civic

civic is palindrome.

Input: deleveled

deleveled is a palindrome.

Input: program

program is not a palindrome.

Input: exit

[…@pc…]