Name: ID: Bil-200 Final
Name: ID: Bil-200 Final
ID:
BIL-200 FINAL (120 min.)
1) (20) In class, we have seen an example about the Fibonacci sequence, in which the first two
numbers are defined to be 1, and each additional number is defined to be the sum of the two
previous numbers. The first several numbers of the Fibonacci sequence are therefore:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
Now we are going to make up the Gibonacci sequence, in which the first three numbers are
defined to be 1, and each additional number is defined to be the sum of the three previous
numbers. The first several numbers of the Gibonacci sequence are therefore:
1, 1, 1, 3, 5, 9, 17, 31, 57, 105, ...
Write a function called gibonacci which accepts, as a parameter, an integer n (assumed
to be positive) and returns the nth Gibonacci number.
HINT: Use recursion.
2) (15) The following code has at least 5 errors. Determine and indicate these errors:
#include <stdio.h>
int main(void)
{
FILE *fpOut;
fpOut = fopen(output.txt, r);
if (fpOut = NULL)
{
printf(Could not create output.txt!\n);
return 1;
}
c = getchar();
while (c != NULL)
{
putchar(c, fpOut);
c = getchar();
}
fclose(fpOut);
return 0;
}
3) (20) Write a function that takes the name of a text file as its input argument, opens the
file for reading, determines and returns the number of lines (separated by <enter>s) in that
text file.
Using this type, you define the following pointer variable inside your main program:
void main(void){
struct family *families;
int i,....
....
....
asks the user how many families he/she would enter (say N),
allocates memory for N families, then
one by one asks N family entries from the user by,
a. first asking how many member persons are there in the family, then
b. allocating the member field of that family according to this number, then
c. asking the age and name of each member, and
d. asking the common address of the family,
and finally displays the whole N families including their members.