Sample CMSC 106 MIDTERM Problems

  1. Write a recursive function which takes an int and returns its factorial.
  2. Write an iterative version of the same function.
  3. Which of the following are legal ANSI C identifiers:
           x       a1b2c3     if
    
    Explain why or why not.
  4. Find the syntax errors in the following code:
    {
    int i,j=0;
    char c;
    scanf("%c',c);
    if (c='A') printf("Everything's Right!\n");
    if (7>0) printf("No it ain't\n")
      esle printf("See I said so.\n");
    }
    
    
  5. What does the following code do:
    int i=0,x[N],r=0;
    while ( i < N )
       {
         if (r == 2*r)
           printf("Never Get Here\n");
         if (r < x[i])
           r = x[i++];
       }
    printf("R is %d\n",r);