Question 2: Show the output (loops and nested loops) [6]
Show the precise output produced by the program below:
#include <cstdio> int main() { int i, j = 0; for (i = 4; i > 0; i--) { j++; printf("i: %d, j: %d\n", i, j); } printf("i: %d, j: %d\n", i, j); int m = 6, n; char c = '*'; do { n = 1; while (n < 3) { printf("%c", c); n++; } printf("\n"); m = m - 2; } while (m != 0); printf("m: %d, n: %d\n", m, n); return 0; } |
Sample solution: i: 4, j: 1 i: 3, j: 2 i: 2, j: 3 i: 1, j: 4 i: 0, j: 4 ** ** ** m: 0, n: 3 |