QUESTION 1 (10 points)

Translate each English phrase into a C expression.  Use any variable name desired.

  1. Nine minus the length of a Giraffe’s neck.

int neck_length, total_length;

total_length = 9 -  neck_length;

  1. The amount in a checking account after 255 hundred dollars is added.

double checking_amount, current_ checking _amount;

current_ checking _amount = checking _amount + 255.0;

QUESTION 2 (10 points)

This program contains syntax errors.  Rewrite the program with the correct syntax.

#include  <stdio.h>

void main();

{

          int          initial_amount = 7654;

          double current_total = 0;

          current_total = intial_amount * 7.75;

          print(“Current total is:  %d\n”, current_total);

}       

SOLUTION:

#include  <stdio.h>

void main()

{

          int          initial_amount = 7654;

          double current_total = 0;

          current_total = initial_amount * 7.75;

          printf(“Current total is:  %lf\n”, current_total);

}       

 

QUESTION 3 (20 points)

Trace the variables x, y, z, and w for each line of the program given the input:

                    8          9          3          4          20

#include <stdio.h>

void main()

{

(1)      int x, y, z, w;

(2)          scanf("%d%d%d%d", &x, &y, &z, &w);

(3)      x = y % z;

(4)      z = y - x;

(5)      w = w + z - x;

(6)      x = x + y + w;

(7)      w = (y/z)%x;

(8)          printf("%d %d %d %d \n", y, x, z, w); 

}

 

#         x            y            z            w

1          ?            ?            ?            ?

2          8            9            3            4

3          0            9            3            4

4          0            9            9            4

5          0            9            9            13

6          22            9            9            13

7          22            9            9            1

8            output:  9  22  9  1

QUESTION 4 (20 points)

Be my

Valentine!!!

!Oh please,

 

oh please

Be my Valentine

QUESTION 5 (20 points)

No, the “while” loop only iterates from through the odds of 1 to 79 and not 81.  This code will add all the odd integers from 1 to 79 but NOT from 1 to 81.

QUESTION 6 (20 points)

This test is almost over.

This test is almost over.

This test is almost over.