Midterm 1 KEY

  1. [10 pts] Short answer:

    1. There will be many answers on this.
      For example:
      i. TRUE: a=1, b = 2, c = 0
      FALSE: a=3, b = 2, c = 3


      ii. TRUE: a=1, b = 1, c = 2
      FALSE: a=1, b = 1, c = 1


      iii. TRUE: a=1, b = 0, c = 1
      FALSE: a=1, b = 0, c = 0

    2. printf("&\\'%%$\"#@:") \n is optional

    3. Again, many answers.
      For example printf("%d", x++).

    4. x : 3, y : 0

  2. [10 pts.]
    1. **2335^3.14^2^^^^^**
      **^3^12^2335**

    2. **01^2.718**
      **6^12.0**

  3. [15 pts]

    
    A  8
    B  8 8
    B  8 16
    B  8 32
    C
    A  4
    B  4 4
    B  4 8
    C
    A  2
    B  2 2
    C
    

  4. [20 pts]
    1. A
    2. No Output
    3. Syntax Error
    4. B
      C
      D
  5. [20 pts] 10 points each
    1. 
        
        i = 0;
        while (i < n)
          {
            printf("%d bottles left\n", n-i);
            printf("I've drunk %d \n", i);
            i ++;
          }
      

    2. 
        printf("%d %d\n", a, b);
        a++;
        b --;
        
        while(a <=b)
          {
            printf("%d %d\n", a, b);
            a++;
            b --;
          }
      

  6. [25 pts.]

    
    #include <stdio.h>
    
    main()
    {
      int power, num, num2, sum ,i;
      
      scanf("%d", &power);
      
      while (power >=0)
        {
          sum =0;
          scanf("%d", &num);
          while(num >=0)
            {
              num2 =1 ;
              for (i = 0; i < power; i ++)
                num2 *= num;
              sum += num2;
              scanf("%d", &num);
            }
          printf("Sum is %d \n", sum);
          scanf("%d", &power);
        }
    }
    




2001-10-18