Whart difference between these two questions . Give me the exxplanation. 1. What
ID: 3866767 • Letter: W
Question
Whart difference between these two questions. Give me the exxplanation.
1. What are the values of i and sum after this code sequence is executed? i is 40
sum is 60
int i = 0;
int sum = 0;
for ( i = 0; i < 40; i++)
{
if ( i % 10 = = 0)
sum += i ;
}
2. What are the values of i and sum after this code sequence is executed?
int i = 0;
int sum = 0;
for ( i = 0; i < = 40; i++)
{
if ( i % 10 = = 0)
sum += i ;
}
i is 40
sum is 60
i is 41
sum is 60
i is 40
sum is 100
i is 41
sum is 100
i is 40
sum is 60
i is 41
sum is 60
i is 40
sum is 100
i is 41
sum is 100
Explanation / Answer
1) For the First one the output after the code execution will be
I = 39
Sum = 60.
2) For the second one the output would be
I= 40
Sum = 100.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.