Computer Applications
Consider the following program segment in which the statements are jumbled. Choose the correct order of the statements to return the sum of first 10 natural numbers.
for(i=1; i<=10; i++) → 1
return sum; → 2
int sum = 0, i; → 3
sum+=i; → 4
- 1 2 3 4
- 3 4 1 2
- 1 4 2 3
- 3 1 4 2
Java Iterative Stmts
7 Likes
Answer
3 1 4 2
Reason — To return the sum of first 10 natural numbers, we must follow the proper sequence of statements:
int sum = 0, i;– Declare the variablessumandi, and initializesumto 0.for(i=1; i<=10; i++)– Start the loop to go through numbers 1 to 10.sum+=i;– Add the current numberitosumduring each loop iteration.return sum;– After the loop completes, return the total sum.
Answered By
3 Likes
Related Questions
Consider the Two dimensional array S[2][3], of storage devices given below, state the index of the Hard disk.
![Consider the Two dimensional array S[2][3], of storage devices given below, state the index of the Hard disk? ICSE 2025 Computer Applications Solved Question Paper.](https://cdn1.knowledgeboat.com/img/abp10/1/q1-18-icse-computer-board-2025-improvement-1133x731.png)
- S[1][0]
- S[0][1]
- S[1][2]
- S[0][0]
How many times the for statement given below is executed?
for(k = 10; k >= 0; k--)- 10
- 11
- 12
- 0
Write Java expression for the following:
Evaluate the given expression when x = 4.
x *= --x + x-- + x;