QUESTION 1 (10 points)

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

  1. Eight times the weight of a Kangaroo.
  2. The amount in a savings account after eight hundred dollars is added.

QUESTION 2 (10 points)

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

 

#include  <stdio.h>

void main();

{

          int          initial_amount = 3027

          float          current_total = 0

          current_total = initial_amount * 7.75;

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

}       

QUESTION 3 (20 points)

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

                    10          11          3          2          19

#include <stdio.h>

void main()

{

          int x, y, z, w;

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

          x = y % z;

          z = y - x;

          w = w + z;

          x = x + y;

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

}

QUESTION 4 (20 points)

Give the output of this code exactly as it appears on the screen.

#include <stdio.h>

void main()

{

printf(“What’s up!”);

printf(“\nWhat’s up!!!”);

printf(“What’s up!!!!!!!!”);

}

QUESTION 5 (20 points)

Will this code add all the even integers from 2 to 40?  Explain.

#include <stdio.h>

void main()

{

          int total = 0, count = 0;

while (count <= 20)

{

                    total = total + 2*count;

                    count = count + 1;

          }

}

QUESTION 6 (20 points)

What gets printed by this code?

#include <stdio.h>

void main()

{

          int j = 3;

          while ( j <= 7 )

          {

                    printf(“Happy Halloween.\n”);

                    j++;

          }

}