1. Preparation
Use the assignment code hw4 to get the files for assignment 4.
test1.c: This program is used to test the isPerfect()( ) function Do NOT change this file test2.c: This program is used to test the isFib()( ) function Do NOT change this file hw4.c: The C program file contains the functions isPerfect() and isFib() You must edit and turn in this file for hw4 |
You must work on assignment 4 in the following way:
|
2. Assignment description
|
The details of these 2 functons are given below (Section 3 and 4)
Use the provided prepared file hw4.c to write the functions:
/* -------------------------------------------------------------
isPerfect(n): returns 1 if n is a perfect number
otherwise returns 0
Suppose f1, f2, ... fk are factors of n (Each: 1 <= f < n)
n is a perfect number if f1 + f2 + ... + fk = n
E.g.: 6 is perfect
Factors of 6: 1, 2, 3 and 1 + 2 + 3 = 6
28 is perfect: 1 + 2 + 4 + 7 + 14 = 28
===============================================================
To compile test1, use this command:
gcc -o test1 test1.c hw4.c
To run test1, use this command:
test1
------------------------------------------------------------- */
int isPerfect(int n)
{
// Write this function for part 1
}
/* -----------------------------------------------------
isFib(n): returns 1 if n is a Fibonannci number
otherwise returns 0
The Fibonacci numbers defined found as follows:
fib(0) = 1
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)
===============================================================
To compile test2, use this command:
gcc -o test2 test2.c hw4.c
To run test2, use this command:
test2
----------------------------------------------------- */
int isFib(int n)
{
// Write this function for part 2
}
|
3. Part 1 of homework 4
|
Use the provided test1.c program to test your isPerfect(n) function.
When you finish writing the isPerfect() function, you can compile and test it with these commands:
Compile: gcc -g -o test1 test1.c hw4.c
If no errors, run it with: test1
If your function passes all the tests, test1 will print out:
Test 1 passed
Otherwsie, it will print out which inputs failed the test
|
4. Part 2 of homework 4
|
Use the provided test2.c program to test your isFib(n) function.
When you finish writing the isFib() function, you can compile and test it with these commands:
Compile: gcc -g -o test2 test2.c hw4.c
If no errors, run it with: test2
If your function passes all the tests, test2 will print out:
Test 2 passed
Otherwsie, it will print out which inputs failed the test
|
5. Extension request
If you need further instructions, read this write up: click here
6. Turn in instructions
If you need further instructions, read this write up: click here