Find the output of the following programs. 1. main() { int a = 10; int b = 10; int c = 10; int d = 10; b = ++a; c = --b; d *= a; if (a < 20) { b++; c++; } else if (b < 20) { d++; a++; } d++; printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c, d); }
2. main() { int a = 10; int b = 10; int c = 10; int d = 10; b = ++a; c = --b; while (a < 20) { b = a++; c++; } if (b < 20) { d *= a; a++; } d++; printf("a = %d\n", a); printf("b = %d\n", b); printf("c = %d\n", c); printf("d = %d\n", d); }
3. main() { int a; for ( a = 0; a < 5; a++) { printf(â&#x20AC;&#x153;%d\nâ&#x20AC;?, a); continue; } }
4. main() { int a; a = 0; while (a < 5) { printf(â&#x20AC;&#x153;%d\nâ&#x20AC;?, a); continue; a++; } }
5. main() { int a = 10; int b = 10; int c = 10; int d = 10; b = ++a; c = --b; while (a < 30) { b = a++; c++; if (b < 20) { d *= a; a++; continue; } d = c * d % 4; d++; } d++; printf("a = %d\n", a); printf("b = %d\n", b); printf("c = %d\n", c); printf("d = %d\n", d); } 6. main() { int a = 'A'; for (i = 0; a >= 'A' && a <= 'D'; i++) printf("%c\n", a + 'a' - 'A'); }
7. main() { int x = 11; int y; for (y = 0; x != 0; x >>= 1) { if (x & 01) y++; } printf("y = %d\n", y); }
8. main() { int a = 10; int b = 10; int c = 10; int d = 10; b = ++a; c = --b; while (a < 30) { b = a++; c++; if (b < 20) { d *= a; a++; continue; } else if (d > 40) { d++; printf("Break\n"); break; } d = c * d % 4; d++; } d++; printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c, d); } 9. main() { int a, b, c, d; a = b = c = d = 10; b = ++a; c = --b; while (a < 30) { b = a++; c++; if (b < 20) { d *= a; a++; while (c < 20) { b = c++; a = b != c; if (c < 40) continue; d++; } continue; } else if (d > 40) { d++; break; } else d = c * d % 4; d++; } d++; printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c, d); }
10. main() { int a, b, c, d; a = b = c = d = 10; b = ++a; c = --b; for (a = 10; a < 30; a++) { b = a++; c++; if (b < 20) { d += a; a++; while (c < 20) { b = c++; a = b != c; if (c < 40) continue; d++; } continue; } else if (d > 40) { d++; break; } else c = c * a % 4; d++; } d++; printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c , d); } 11. main() { int a, b, c, d; a = b = c = d = 10; b = ++a; c = --b; for (a = 10; a < 30; a++) { b = a++; c++; for (a = 10; a < 30; a++) { if (b < 20) { d += a; a++; while (c < 20) { b = c++; a = b != c; if (c < 40) continue; d++; } continue; } else if (d > 40) { d++; break; } else c = c * a % 4; d++; } d++; } printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c, d); }
12. main() { int a = 10; int b = 10; int c = 10; int d = 10; for (; a < 30; a++) { printf("1st for\n"); c++; for (c = 10; ;) { printf("2nd for\n"); d++; printf("b = %d\n", b); if (b < 20) { d += a; b++; for (; ;) { c++; printf("3nd for\n"); a = b != c; if (c > 20) break; d++; } continue; } else { a++, b++, c++; break; } } d++; } printf("a = %d\n", a); printf("b = %d\n", b); printf("c = %d\n", c); printf("d = %d\n", d); } 13. main() { int a = 10; int b = 20; while (a < 15) a++; b++; printf(“a = %d, b = %d”, a, b); }
14. main() { int a; int b; for (a = 0, b = 0; a < 5; a++, b++) b++; printf(“a = %d b = %d\n”, a, b); }
15. main() { int a = 10; int b = 10; int c = 10; int d = 10; int e = 10; int f = 20; for (; a < 30; a++) { printf("1st for\n"); for (; ;) { c++; e++; if (c > 20) { e %= 2; break; while (f < 10) { f++; continue; } } else { e--; continue; } } for (c = 10; ;) { printf("2nd for\n"); d++; printf("b = %d\n", b); if (b < 20) { d += a; b++; for (; ;) { c++; printf("3nd for\n"); a = b != c; if (c > 20) break; d++; } continue; } else { a++, b++, c++; break; } } d++; } printf("a = %d\n", a); printf("b = %d\n", b); printf("c = %d\n", c); printf("d = %d\n", d); printf("e = %d\n", e); printf("f = %d\n", f); }