_AG_Test_2_Questions-1

_AG_Test_2_Questions-1 - CIS 15AG 1 Test 2 Questions:...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 15AG Test 2 Questions: Chapters 1-8, emphasizing 6, 7, and 8. "Computers are good at following instructions, but not at reading your mind." - Donald Knuth _____________________________________________________________________________________ 1. Loops (A) Predict the output: (B) Predict the output. The initial value of x is 5638 1 for( i = 1; i < 4; i++ ) { printf( "Iteration number %d ", i ); printf( "Hello again!\n" ) } printf( "All done!\n" ) int guess (int x) { int rx; int d; rx = 0; while( x > 0 ) { d = x % 10; rx = rx*10 + d; x /= 10; } return rx; } Answer: Iteration # d rx initial value 0 x initial value 5638 x > 0 ? True 1 2 3 4 Returned value:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CIS 15AG Test 2 Questions: Chapters 1-8, emphasizing 6, 7, and 8. (C) Rewrite the following function using the correct indentation. int fun( int num ){ int d;int p;int s;p=1;d=2; s=(int)sqrt(num);while(d<=s && p) {if(num%d==0) p=0;d++;} return p;} (D). Nested loops. Predict the output 2 for( i = 5; i <= 7; i++ ) for( j = 1; j <= 3; j++ ) printf( "%2d%2d\n", i,j ); Answer: i i <= 7 j j <= 3 Output
Background image of page 2
CIS 15AG Test 2 Questions: Chapters 1-8, emphasizing 6, 7, and 8. _____________________________________________________________________________________ 2 . Arrays (A). Determine which one of the following assignments is not valid, given the declarations: char listA[50]; int listB[50]; int listC[50]; char ch = 'X'; int num = 25; a. listC[0] = num; b. listB[50] = 99; c. listA[0] = ch ; d. listA[2*num – 1] = ch + 1; e. listA = listB; (B) What is displayed after execution of the following program fragment? Assume the input data is 85 AB 4 2 6 9519CD ^^^^^^^^^^^^^^^^^^^^^ // to help you keep track of the number of spaces int list[4]; char word[4]; int k; for ( k = 0; k < 4; k++ ) { scanf("%d", &list[k]); scanf(" %c", &word[k]); scanf("%c", &word[k]); } for ( k = 0; k < 4; k++ ) { printf("%c", word[k]); printf("%d", list[3 - k]); } 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CIS 15AG Test 2 Questions: Chapters 1-8, emphasizing 6, 7, and 8. _____________________________________________________________________________________ 3
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Spring '10 term at DeAnza College.

Page1 / 11

_AG_Test_2_Questions-1 - CIS 15AG 1 Test 2 Questions:...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online