Skip to content

Instantly share code, notes, and snippets.

@rszewczyk
Last active December 5, 2017 23:11
Show Gist options
  • Save rszewczyk/7f56841189e371a257f7b40daa1bb16f to your computer and use it in GitHub Desktop.
Save rszewczyk/7f56841189e371a257f7b40daa1bb16f to your computer and use it in GitHub Desktop.
CMSC 104 Final Exam Review

Practice Final - Answers

1.

Remove the & on line 8

Change %C to %s on line 10

2.

A recipe for making pancakes

Finding the GCD of two numbers

3.

The topic in which you need to have knowledge in order to solve a particular problem.

4.

even
1
even
3
even

5.

1
2
3
5
8
13

6.

Add a line after line 98. That line should be number = number + 1;

7.

Change line 13 to int number = -1;

8.

4
6
8

9.

0
2
4
5
6
7
8
9

10.

8

11.

change line 9 to while (currentIndex < 5)

swap line 11 with line 12

Sample Final Exam

1.

Identify two errors in the program below and describe how to correct them.

#include <stdio.h>

int main()
{
  char aWord[50];

  printf("Enter a word and press enter: ");
  scanf("%s", &aWord);

  printf("The words is: %C\n", aWord);
}

2.

List two examples of an algorithm

3.

Define problem domain

4.

Write the output of the following program

#include <stdio.h>

int main()
{
  int number = 0;

  while (number < 5)
  {
    if (number % 2 == 0)
    {
      printf("even\n");
    }
    else
    {
      printf("%d\n", number);
    }

    number = number + 1;
  }
}

5

Write the output of the following program

#include <stdio.h>

int main()
{
  int number = 1;

  int previous1 = 1;
  int previous2 = 0;

  while (number < 7)
  {
    int current = previous1 + previous2;
    printf("%d\n", current);

    previous2 = previous1;
    previous1 = current;

    number = number + 1;
  }
}

6.

Identify the error in the following program and describe how you would correct it:

#include <stdio.h>

int main()
{
  int number = 0;

  printf("The first ten integers starting at 0 are:\n");
  while (number < 10)
  {
    printf("%d\n", number);
  }
}

7.

Identify the error in the following program and describe how you would correct it:

#include <stdio.h>

int main()
{
  int number = 0;

  while (number < 0)
  {
    printf("Enter a non negative integer: ");
    scanf("%d", &number);
  }

  printf("You entered: %d\n", number);
}

8.

Write the output of the following program:

#include <stdio.h>

int main()
{
  int number = 0;

  while (number < 10)
  {
    if (number % 2 == 0 && number >= 4)
    {
      printf("%d\n", number);
    }

    number = number + 1;
  }
}

9.

Write the output of the following program:

#include <stdio.h>

int main()
{
  int number = 0;

  while (number < 10)
  {
    if (number % 2 == 0 || number >= 4)
    {
      printf("%d\n", number);
    }

    number = number + 1;
  }
}

10.

Write the output of the following program:

#include <stdio.h>

int main()
{
  int numbers[5] = {4, 6, 8, 1, 5};

  int currentIndex = 1;
  int val = numbers[0];
  while (currentIndex < 5)
  {
    if (numbers[currentIndex] > val)
    {
      val = numbers[currentIndex];
    }

    currentIndex = currentIndex + 1;
    }

  printf("%d\n", val);
}

11.

Identify the errors in the following program and describe how to correct them

#include <stdio.h>

int main()
{
  int numbers[5] = {1, 7, 3, 2, 7};

  printf("Printing 5 values in the array:\n");
  int currentIndex = 0;
  while (currentIndex <= 5)
  {
    currentIndex += 1;
    printf("%d\n", numbers[currentIndex]);
  }
}
  • Class 14
    • define string
    • be familiar with how to use:
      • printf to print a string
      • scanf to get string input from a user
  • Class 15 - be able to define and answer question in your own words about:
    • algorithm
    • problem domain
  • Class 16, 17 & 18
    • Identify important parts of a while loop
      • loop control variable
      • conditional expression
      • loop body
    • Be able to look at a simple while loop and identify what it is doing (e.g. what's the output)
    • Identify syntax and logic errors associated with while loops
  • Class 19
    • Be able to identify relational and logical operators
    • Evaluate simple logical expressions
  • Class 21 & 22
    • Define array index
    • Be able to declare and array of a particular size for a particular data type
    • Be able to evaluate the result of simple programs that use arrays
    • Be able to identify syntax/logic errors in programs with arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment