CSCI 102 - Fall 2023 Fundamentals of Computation

Week 8 Lab

Q&A on Material

Sign in to lab!

Exercises

Tracing exercise

Walk through these exercises and complete them as a group (if time allows):

Determine what the following code will print.

#include <iostream>
using namespace std;

int main()
{
  int a = 24, b = 9, x, y;
  for(int i=2; i <= 4; i++){
    x = a;
    y = b;
    while( y != 0 ){
      int t = y;
      y = x % y;
      x = t;
    }
    cout << x << endl;
    a += 3;
    b *= i;

  }
  return 0;
}

Solution

Coding exercises

cpp/cs102/lab9/gcd-nested

Open-ended Help

Any students with questions may stay after to get help. Anyone else may leave at this stage.