Creview

Creview - for (ctr2 = 3; ctr2 > ctr1; ctr2-- ) {...

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

View Full Document Right Arrow Icon
Midterm Review ENGR3, Summer Session B 2006 1. Write a for loop that is equivalent to the statements: int ctr = 50; while(ctr <= 75) { printf( “%5d”, ctr ); ctr += 2; } 2. What is printed by the following code? j = 5; while (j > 0) { if (j > 2) { j -= 2; printf(“%d\n”, j); continue; } else { printf(“%d\n”, --j); } printf( “You’re doing great!” ); } 3. Rewrite the following statement using the ternary conditional operator: if ( x % 2 = = 0 ) { printf( “x is even” ); } else { printf( “x is odd” ); } 4. What is printed by the following code slice (be very careful on this one, and be sure to state the output exactly as it is): int ctr1, ctr2; for (ctr1 = 3; ctr1 > 0; ctr1-- ) {
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (ctr2 = 3; ctr2 > ctr1; ctr2-- ) { printf(%d, ctr1); } printf(\n); } 5. Rewrite this program. Fix all the errors in the following code to make this program do what it is supposed to. include (stdio.h) include (math.h) main() { int a=5, b=4, c, d; (int) (sqrt(a+b) ) = c; printf(Input d:) scanf(%f, d); if (d = c) { printf(d is equal to c.\n); } else { printf(d is not equal to c.\n); } return 0; } 6. Write a program which prompts the user to enter 2 integers a and b and then outputs . The header and the end of the program are done for you. ) 1 ln( 2 3 b a + + #include <stdio.h> #include <math.h> int main() { return 0; }...
View Full Document

This note was uploaded on 08/06/2010 for the course ENGR 3 taught by Professor Ben-yaakov during the Summer '08 term at UCSB.

Page1 / 2

Creview - for (ctr2 = 3; ctr2 > ctr1; ctr2-- ) {...

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

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