Vidyalelo
Data Structure · Q919

Miscellaneous on Data Structures

Programming · Data Structure · question 919

Q919

Consider the following iterative solution to find the sum of first n natural numbers: #include int get_sum(int n) int sm = 0, i; for(i = 1; i <= n; i++) ________; return sm; int main() int n = 10; int ans = get_sum(n); printf("%d",ans); return 0; Which of the following lines completes the above code?

A.
sm = i
B.
sm += i
Answer
C.
i = sm
D.
i += sm

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board