owner sign in

Problems

Exercise

In section 0.5.4, the modulo operator is used in the primality() function to compute modulo 2. Calculate 14 % 7, 6 % 21, and 35 % 9.

Exercise

In the primality() function of section 0.5.4, the loop condition is i < max_divisor+1. Explain why changing it to i < max_divisor causes primality() to mistakenly identify 121 as a prime number.

Exercise

Write a C program that meets the following requirements:

  1. It includes a function

    int factorial(int n);

    The function factorial() should compute the factorial of n.

  2. It has a main() function that tests the factorial() with inputs of 0, 1, and 8.

  3. It prints the computed factorials.