APSC160-sampleMidterm#1_solution

APSC160-sampleMidterm#1_solution - Section 1 Short Answer...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Section 1: Short Answer Q1A. Consider the following code segments: What Boolean expression can be inserted in place of *** in the code segment on the right so that these two code segments produce exactly the same output for every possible value of num1 and num2 ? ( num1 > 9 && num2 < 12 ) Q1B. What value should be used in place of *** in the code segment below so that count has the value 20 when the code segment has executed? int count = 0; int indexA = 0; int indexB; while( indexA < *** ) { indexB = 0; while( indexB < 5 ) { count++; indexB++; } indexA++; } 4 Q1D. Consider the following code segment: if( num1 < 2 || num2 > 7 ) printf( "A" ); if( num2 > 9 ) printf( "B" ); else printf( "C" ); What is printed on the screen when this code segment runs assuming that num1 and num2 are variables of type int and that num1 has the value 4 and num2 has the value 8? AC if( num1 > 9 ) { if( num2 < 12 ) printf( "A" ); } printf( "B" ); if( *** ) printf( "A" ); printf( "B" );
Image of page 1

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

View Full Document Right Arrow Icon
Page 2 of 5 Q1E. Consider the following code segment: int count = 1; int sum = 0; while( count < 6 && sum < 7 ) { sum += count; count++; } printf( "sum = %d, count = %d\n", sum, count ); What is printed on the screen when this code segment runs?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern