Name: ____________________________________________________ Alpha: _____________ Section: ________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

Due: Before 0800 on next class day

  1. (10 pts) Read today's lecture notes. Honestly declare how you read the notes.
    1. (10 pts) I read the notes carefully. I have a good understanding of the topics therein.
    2. (10 pts) I read the notes carefully, but I don't really understand the following points well:
      
      
      
    3. (0 pts) I didn't read the notes carefully.
  2. [90pts] Change the following C++ program to C (with filename hw.c). You must verify correctness by compiling with gcc:
    // A fancy C++ program that calculates n!
    #include <iostream>
    using namespace std;
    
    int factorial(int);
      
    int main() 
    {
      int num;
      cout << "Enter a number: ";
      cin >> num;
    
      int fac = factorial(num);
      cout << num << "! = " << fac << endl;
      
      return 0;
    }
    
    // Compute n!
    int factorial(int n) 
    {
      int prod = 1;
      for( int i = 1; i <= n; i++ ) 
        prod *= i;
      
      return prod;
    }
    Example runs:
    ~/$ ./hw
    Enter a number: 4
    4! = 24
    
    ~/$ ./hw
    Enter a number: 8
    8! = 40320
    

    Submit to the submission server (due: 0800 on the next class day)

    ~/bin/submit -c=IC210 -p=hw37 hw.c
    
    Bring to class
    • A printout of this homework sheet annotated with your answers
    • The codeprint of hw.c