I'm having problem with this piece of code:
#include %26lt;stdio.h%26gt;
#include %26lt;conio,h%26gt;
void main( )
{
int y=0, r=0, c=8;
do{
clrscr( );
printf(“value:”); scanf(“%d ”, %26amp;y);
if (y = = 0)
r = r+1;
}while(y%26lt;=100);
printf(“ r = %d”, r);
}
****
ok, now my question is:
does this determine:
a) counts the number of zeros entered in n numbers that are lower than 101
b) counts the number of zeros entered in n numbers that are lower than 100
really having trouble with this, already did many tests but can't get to a conclusion, any help would be greatly appreciated.
C++ little problem?
Look at this from your program:
while(y%26lt;=100);
What this means is that the code in the loop will execute when the condition is true. In this case, the condition is that y is less than or equal to 100. So, when y is 100 the loop will still execute. But that is it. It will not work past 100. That means that it will count the numbers until it gets to 100 -100 will be counted.
So a) is the correct answer.
Reply:Choice a is the answer.
Reply:Entering in 100 would not get counted but the loop continues.
Entering 101 would not get counted and the loop would stop.
I would say both answers are correct. But, to stop the loop A would be the answer.
bad question though...if they are trying to teach while loop condition stops. Bad bad....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment