This browser does not support JavaScript. In order to use this test, please update your browser to a JavaScript compatible browser, or choose the CGI version of this test. Internet Explorer browsers are updated by http://www.microsoft.com/ie/, and Netscape browsers updated by accessing http://www.netscape.com/
1. The statement which prints out the values 1 to 10 on separate lines, is
Statement 1
for( count = 1; count <= 10; count = count + 1) printf("%d\n", count);
for( count = 1; count < 10; count = count + 1) printf("%d\n", count);
for( count = 0; count <= 9; count = count + 1) printf("%d ", count);
for( count = 1; count <> 10; count = count + 1) printf("%d\n", count);
2. The statement which produces the following output is, (hint: use two nested for loops)
1 22 333 4444 55555
for(a = 1; a <= 5; a = a + 1) { for( b = 1; b <= 5; b = b + 1) printf("%d", b); printf("\n"); }
for( a = 1; a <= 5; a = a + 1) { for( b = 1; b <= a; b = b + 1) printf("%d", a); printf("\n"); }
for( a = 1; a <= 5; a = a + 1) { for( b = a; b <= 5; b = b + 1) printf("%d", b); printf("\n"); }
for( a = 1; a <= 5; a = a + 1) { for( b = 1; b < a; b = b + a) printf("%d", b); printf("\n"); }
3. The statement which sums all values between 10 and 100 into a variable called total is, assuming that total has NOT been initialised to zero.
for( a = 10; a <= 100; a = a + 1) total = total + a;
for( a = 10; a < 100; a = a + 1, total = 0) total = total + a;
for( a = 10; a <= 100, total = 0; a = a + 1) total = total + a;
for( a = 10, total = 0; a <= 100; a = a + 1) total = total + a;
4. The statement that prints out the character set from A-Z, is
for( a = 'A'; a < 'Z'; a = a + 1) printf("%c", a);
for( a = 'a'; a <= 'z'; a = a + 1) printf("%c", &a);
for( a = 'A'; a <= 'Z'; a = a + 1) printf("%c", a);
for( a = 'Z'; a <= 'A'; a = a + 1) printf("%c", a);
©Copyright B Brown. 1984-1999. All rights reserved.