YCP Logo CS 200, Fall 2007 --- Exam 1 Solutions

1.

  • 13
  • 173

2.

  • 111111
  • 1110111

3.

3 3

4.

2
3

5.

#include <stdio.h>

int main(void){
        double value[20];
        int num_values, i;

        int count;

        printf("How many values? ");
        scanf("%i", &num_values);
        for (i = 0; i < num_values; i++) {
        scanf("%lf", &value[i]);
        }

        count = 0;
        for (i = 0; i < num_values; i++) {
                if (value[i] >= 10.0) {
                        count++;
                }
        }

        printf("%i values were >= 10\n", count);

        return 0;
}

6.

#include <stdio.h>

int main(void){

        double a, b;

        printf("Enter 2 values:\n");

        scanf("%lf %lf", &a, &b);

        if (a < b) {
                printf("min is %f\n", a);
                printf("max is %f\n", b);
        } else {
                printf("min is %f\n", b);
                printf("max is %f\n", a);
        }

        return 0;
}

7.

(0,0) (0,1)
(1,0) (1,1)
(2,0) (2,1)
(3,0) (3,1)

8.

#include <stdio.h>

int main(void){
        int min, max, i;

        printf("Enter min and max values: ");
        scanf("%i %i", &min, &max);

        for (i = min; i <= max; i++) {
                if (i % 6 == 0) {
                        printf("%i ", i);
                }
        }
        printf("\n");

        return 0;
}

10.

#include <stdio.h>

int main(void){

        int j, i, fac, superfac, n;

        printf("positive integer? ");
        scanf("%i", &n);

        superfac = 1; // superfactorial of 1 is 1

        for (j = 2; j <= n; j++) {
                // Compute the factorial of j
                fac = 1;
                for (i = 2; i <= j; i++) {
                        fac = fac * i;
                }

                // update superfac
                superfac = superfac * fac;
        }

        printf("superfactorial of %i is %i\n", n, superfac);

        return 0;
}

11.

===
==
=
=
==
===

Bonus Question.

-66