What will be value of sum after execution of the statement? for(i=1, sum=0; i<=5; i++) sum+=i; (i) 13 (ii) 15 (iii) 25 (iv) Error in statement.
Answers
Answered by
0
Answer:
20 cm dgj 50 r geto 24 mm dvh
Answered by
2
The value of sum after execution of the statement is Option (ii) 15
Explanation:
for(i=1,sum=0;i<=5;i++)
sum+=i ;// this statement can also be written as sum=sum+i
initially i=1 ,1<=5 so sum=sum+i so 0+1=1
sum=1
Then, value of i will be incremented as i++, i=2
Sum=1+2=3
now i=3,3<=5 sum=3+3=6
now i=4,4<=5 sum=6+4=10
now i=5,5<=5 sum=10+5=15
now i=6,6<=5, now the condition becomes false so it will end the for loop.
Output is 15.
Similar questions
Math,
5 months ago
English,
5 months ago
Social Sciences,
5 months ago
Computer Science,
9 months ago
Computer Science,
9 months ago
Psychology,
1 year ago
Math,
1 year ago