Classwork 7: If Else Conditionals

Tuesday, July 24, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Create the file cw07.c for a classwork assignment and start your file as normal.
  2. Note you may use functions if you want, it might make the work easier, but you are not required to.
  3. Write a program that will allow the user to test if two numbers are both factors of a third number.
  4. The user should be prompted for all three numbers, a number and then two possible factors
  5. The program should print "TWO FACTORS" if both tested number were factors, "ONE FACTOR" if only one number being tested was a factor, or "NO FACTOR" if no number being tested was a factor.
  6. Example: 12, 3, 4 would print "TWO FACTORS" (since 3 and 4 are factors of 12)
  7. Example: 99, 9, 7 would print "ONE FACTOR" (since 9 is a factor of 99, but 7 is not)
  8. Example: 100, 30, 9 would print "NO FACTOR" (since neither 30 nor 9 is a factor of 100)
  9. EXTRA CREDIT: Modify the program to print (in addition to the above) "NON-DISTINCT FACTORS" if the two numbers being tested are the same or one is a multiple of the other (eg. 3 and 9, or 12 and 48)
  10. Once you are sure the program is done and working well, start a script using script
  11. Once the script is running, show you running the program three times, make sure you show all three possible results typing in different values each time. If you complete the extra credit, also show two additional runs, one with equal test numbers, and one with one being a multiple of the other.
  12. Exit from the script, which will save the log typescript
  13. Once you are done, use submit to submit two files, cw07.c and typescript

    linux3[26]% submit cs104 cw07 cw07.c typescript
    

  14. After submitting your files, you can verify your files were submitted by using the submitls command
  15. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!