Order PDF of any content from our website with a little minor Fee to donate for hard work. Online MCQs are fully free but PDF books are paid. For details: contact whatsapp +923028700085 Important notes based PDF Books are available in very little price, starting from 500/-PKR; Order Now: contact whatsapp +923028700085

Past Papers CS201- Midterm Solved Questions on Loops and Operators

Q#1: Why is the modulus operator essential for finding even numbers in C, and what alternative method is suggested in the paragraph?
Answer: The modulus operator % is commonly used to check whether a number is even or odd. If number % 2 == 0, the number is even. An alternative method suggested is using the expression (number / 2) * 2 == number. If this expression equals the original number, then the number is even.


Q#2: What is the consequence of omitting the statement number = number + 1; in the while loop of the program?
Answer: If the statement number = number + 1; is omitted, the value of the variable number will never change. As a result, the loop condition will always remain true, causing an infinite loop where the program keeps running without stopping.


Q#3: Explain the property of the while loop mentioned in the paragraph.
Answer: The while loop has the property that it may execute zero or more times. If the condition is false at the beginning, the loop body will not execute at all. If the condition is true, the loop will continue executing until the condition becomes false.


Q#4: What distinguishes the do-while loop from the while loop, and in what situations is the do-while loop preferred?
Answer: In a while loop, the condition is checked before executing the loop body, so the loop may not execute at all if the condition is false. In a do-while loop, the condition is checked after executing the loop body, ensuring that the loop body executes at least once. The do-while loop is preferred when a task must be performed at least once before checking the condition.

Contents Copyrights Reserved By T4Tutorials