{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

_AG_Test_2_Questions-1

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

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

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:

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

View Full Document
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
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

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

View Full Document
CIS 15AG Test 2 Questions: Chapters 1-8, emphasizing 6, 7, and 8.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online