ooo T-Mobile LTE 11:33 AM blackboardlearn.utep.edu 4 of 5 9 #include 13 12e int
ID: 3669041 • Letter: O
Question
ooo T-Mobile LTE 11:33 AM blackboardlearn.utep.edu 4 of 5 9 #include 13 12e int mainC printfCI shall do my homeworkin): 19 printf("The final value of i is: Nd", idx); How many times does the loop execute? What does the printf statement in line 19 print Now can we increase the repetitions to 1007 The for loops are infamous for always yielding a 1 esecution mistake, ie. we think it's going to run 10 ten times and it ends up running just 9 or 11! Let's practice this Now may times will the loop execute and what is the final value ofid? Expression forfx- 0:idx10: ManyU, I don't Note: this will execute 2-1 timed So Pretty simple, right? Well, let us spice it up a bit more. When we start moditying the loop incrementer we can obtain some-nteresting behaviors. Check this code for counting. Disclaimer: these are not the interesting behaviers 12e int main 13 14 15 forCcount 1; countExplanation / Answer
1)How many times does the loop execute?
Ans:
The for loop executes 5 times (values 0 to 4 only)
2)What does the pirntf statement in line 19 print?
Ans:
The line 19 code: printf("The final value of idx is: %d", idx);
Here the printf statement displays as below:
The final value of idx is: 5
3)How can we increase the repition to 100?
Ans:
Just change the for loop as below:
for( idx = 0; idx < 99; idx++ )
{
}
printf("The final value of idx is: %d", idx);
Which results The final value of idx is: 100.
4)
Expression
Loop
final value of idx
Expected
Actual
Expected
Actual
For(idx = 0; idx < 10; idx++)
<10
0to9(10 times)
<10
10
For(idx = 0; idx <= 10; idx++)
10
10
10
11
For(idx = 5; idx < 10; idx++)
<10
5 to 9 (5 times)
<10
10
For(idx = 10; idx > 7; idx--)
>7
10, 9, 8 (3 time)
>7
7
For(idx = 0; idx == 10; idx++)
10
0
10
0
For(idx = 0; idx != 10; idx++)
!=10
0 to 9 (10 times)
!=10
10
For(idx = 0; idx != -1; idx++)
Many
I don’t know
Many
infinit
5) How many times does the loop execute?
Ans:
for(count = 1; count < 10; count ++)
{
printf("%d ", count);
}
The for loop executes 9 times (values 1 to 9 only)
6) How many times now?
Ans:
for(count = 1; count < 10; count = count + 2)
The for loop executes 5 times (values 1, 3, 5, 7, 9 only)
7) How many times now?
Ans:
for(count = 1; count < 10; count = count + 200)
The for loop executes 1 time (values 1 only).
Expression
Loop
final value of idx
Expected
Actual
Expected
Actual
For(idx = 0; idx < 10; idx++)
<10
0to9(10 times)
<10
10
For(idx = 0; idx <= 10; idx++)
10
10
10
11
For(idx = 5; idx < 10; idx++)
<10
5 to 9 (5 times)
<10
10
For(idx = 10; idx > 7; idx--)
>7
10, 9, 8 (3 time)
>7
7
For(idx = 0; idx == 10; idx++)
10
0
10
0
For(idx = 0; idx != 10; idx++)
!=10
0 to 9 (10 times)
!=10
10
For(idx = 0; idx != -1; idx++)
Many
I don’t know
Many
infinit
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.