- Four answers: four integers for initial values of n = 1, n = 2,
n = 4, n = 100
int i = 0;
s1 while (i < n)
s2 { for (int j = 0; j < n; j++)
s3 cout << "Hello world";
s4 i = i + 1;
}
- One answer: an integer
s1 for (int i = 1; i <= 6; i++)
s2 for (int j = 1; j <= 10; j++)
s3 cout << i * j << endl;
s4 for (int k = 0; k < 1000; k++)
s5 cout << "Hello" << end;
- One answer: in terms of n
s1 cin >> n;
s2 for (int i = 1; i <= n + 6; i++)
s3 for (int j = 1; j <= n + 10; j++)
s4 cout << i * j << endl;
s5 for (int k = 1; k <= n + 1000; k++)
s6 cout << "Hello" << end;
- Five answers: five integers for initial values of n = 1, n = 4,
n = 6, n = 7, n = 8
s1 while (n > 1)
s2 { cout << n << endl;
s3 n = n / 2;
}
- One answer: in terms of n
s1 cin >> n;
s2 for (i = 1; i <= n; i++)
s3 { temp = n;
s4 while (temp > 0)
s5 { cout << n * temp << endl;
s6 temp = temp / 2;
}
}
- Three answers: three integers based on
x = {3, 6, 9, 4, 18, 10, 12, 1, 0, 16} and
a) q = 3, b) q = 2, c) q = 10
s1 for ( i = 0; i < 10; i++)
s2 { if (q == x[i])
s3 { cout << "q is in array at position " << i;
s4 exit(0);
}
}
s5 cout << "q is not in array"