clear

fprintf ( '\n' );
fprintf ( 'Question 1:\n' );
fprintf ( '\n' );

for i = 1 : 4
  if ( i == 1 )
    a = 2;
  else
    a = a^2 - 1;
  end
  fprintf ( '%d\n', a );
end

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 2:\n' );
fprintf ( '\n' );

i = 0;
while ( i <= 7 )
  b = i - 3;
  i = i + 2;
end
fprintf ( 'i = %d, b = %d\n', i, b );

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 3:\n' );
fprintf ( '\n' );

c = 5;
for k = 0 : 3
  c = c + 2 * k + 1;
end
fprintf ( 'c = %d\n', c );

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 4:\n' );
fprintf ( '\n' );

d = 10;
e = 1;
while ( true )
  d = d - 2;
  if ( d <= e )
    break;
  end
  e = e + 1;
end
fprintf ( 'd = %d, e = %d\n', d, e );

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 5:\n' );
fprintf ( '\n' );

e = 96;
if ( e > 100 )
  e = e - 10;
else
  e = e + 10;
end

if ( e > 100 )
  e = e - 5;
else
  e = e + 5;
end
fprintf ( 'e = %d\n', e );

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 6:\n' );
fprintf ( '\n' );

f = 6;
if ( 10 < f )
  f = f + 5;
elseif ( 0 <= f && f <= 4 )
  f = f - 5;
else
  f = f + 2;
end
e = 12;
g = gcd ( e, f );
e = e / g;
f = f / g;
fprintf ( 'e = %d, f = %d, g = %d\n', e, f, g );

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 7:\n' );
fprintf ( '\n' );

e = 1;
f = 2;
g = 3;
e = f + g;
f = g + e;
g = e + f;
fprintf ( 'e = %d, f = %d, g = %d\n', e, f, g );

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 8:\n' );
fprintf ( '\n' );

for i = 1 : 3
  for j = 1 : i
    h = i + j;
    fprintf ( '%d\n', h );
  end
end

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 9:\n' );
fprintf ( '\n' );

for i = 1 : 5

  if ( i == 1 )
    g = 1;
  elseif ( i == 2 )
    gold = g;
    g = 3;
  else
    golder = gold;
    gold = g;
    g = gold + golder;
  end
  fprintf ( '%d\n', g );
end

fprintf ( 'Press RETURN:' );
pause
clear

fprintf ( '\n' );
fprintf ( 'Question 10:\n' );
fprintf ( '\n' );

a = 10;
b = 6;
while ( 0 < b )
  r = mod ( a, b );
  a = b;
  b = r;
end

fprintf ( 'a = %d, b = %d\n', a, b );

fprintf ( 'Press RETURN:' );
pause
clear

