CSSE 120 -- Intro. to Software Development

Homework 23

  1. Don't forget to refer to the Python vs C comparison document. You may find this helpful as you try to do things in C that you already know how to do in Python. Feel free to suggest things that we might add to this document.
  2. There is no Angel quiz for the next session.
  3. You must do this assignment using Eclipse and the ThatsPerfect project that you checked out from your individual SVN repository in class.

    Be sure to check out that project into your Eclipse C workspace, not your Python workspace.

  4. In the source file perfect.c, edit the initial comment to include your name and today's date.
  5. Edit the main() function so that it uses a sentinel while loop, printf(), and scanf() to prompt the user to enter integers. Exit the loop when the user enters a negative number. Otherwise, just print the value the user entered and prompt for another number.

    When you have this part working, commit it to your repository and go on to the next step.

  6. A perfect number is one that is the sum of its factors. For example, 6 and 28 are perfect because 1+2+3=6 and 1+2+4+7+14=28. But 24 is not perfect because 1+2+3+4+6+8+12 is not 24.

    Define a function

        int isPerfect(int n)
    

    that returns 1 if n is perfect and 0 if it is not perfect.

    Do not attempt to find a closed-form solution. Instead, actually compute the factors of n and add them together.

  7. Change the while loop you created in step 5 so that it prints whether or not the entered number is perfect. A sample run of the program might be:
    	Enter an integer (negative to quit): 6
    	6 is perfect.
    
    	Enter an integer (negative to quit): 24
    	24 is not perfect.
    
    	Enter an integer (negative to quit): 28
    	28 is perfect.
    
    	Enter an integer (negative to quit): -1
    	Goodnight, Gracie.
    

    When you have this part working, commit it to your repository and go on to the next step.

  8. The first two perfect numbers are 6 and 28. Modify your program so that after the interactive part, but before exiting, it calculates and prints the fourth perfect number. This number is quite large, so your program might take a while to run.

    When you have this part working, commit it to your repository and enjoy a refreshing beverage.