Examveda

Consider the following iterative solution to find the sum of first n natural numbers:
#include<stdio.h>
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

C. i = sm

D. i += sm

Answer: Option B


This Question Belongs to Data Structure >> Miscellaneous On Data Structures

Join The Discussion

Related Questions on Miscellaneous on Data Structures