Corrections Found on Book 2010

 

 

Page 48:  The two lines in step 4 were corrected so that the correct solution is as below:

 

MainAlgorithm

Begin

Input:  N (integer);

Output: prime = 0 (boolean);         /* initially set to be non-prime  */

Other:  Remainder, Divisor (integer);

Step 1: Read (N);

Step 2:  Divisor = 2;                    /* keep a number lower than N */

Step 3: if  (N < 2)  prime = 0;  go to step 5;

     else  if  (N = =2) prime = 1;  go to step 5;

Step 4:

     /* If remainder after dividing N by any number lower than N is zero,

              Then N cannot be declared a prime                 */

    

     if  ((Remainder =  N % Divisor) = = 0) prime = 0; go to step 5;

       else  prime = 1; Divisor = Divisor + 1;  if (Divisor < N) go to step 4;

Step 5: if (prime = = 1) print (“Number N is a prime number);

        else print (“Number N is not a prime);

End

 

 

 

Page 157:  All the else’s in the solution are taken out so that the correct solution is as below:

 

#include <stdio.h>

int main(void)

            {

                        int x1, x2, x3, x4, x5, max ;

scanf(“%d %d %d %d %d”, &x1, &x2, &x3, &x4, &x5) ;

max = x1;

if(x2 > max)

   max = x2;

if(x3 > max)

   max = x3;

if(x4 > max)

   max = x4;

if(x5 > max)

   max = x5;

printf(“The maximum of the 5 numbers is %d\n”, max);

return 0;

}