**DOWNLOAD FREE PDF** **<<CLICK HERE>>**

## Data Structure Questions and Answers-Sum of n Natural Numbers using Recursion

Congratulations - you have completed *Data Structure Questions and Answers-Sum of n Natural Numbers using Recursion*.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%

Your answers are highlighted below.

Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

Which of the following methods can be used to find the sum of first n natural numbers?

Iteration | |

Recursion | |

Binomial coefficient | |

All of the mentioned |

Question 1 Explanation:

All of the above mentioned methods can be used to find the sum of first n natural numbers.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

Which of the following gives the sum of the first n natural numbers?

nC2 | |

(n-1)C2 | |

(n+1)C2 | |

none of the mentioned |

Question 2 Explanation:

The sum of first n natural numbers is given by n*(n+1)/2, which is equal to (n+1)C2.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

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?

sm = i | |

sm += i | |

i = sm | |

i += sm |

Question 3 Explanation:

The line "sm += i" completes the above code.

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

What is the output of the following code?

#include<stdio.h> int get....sum(int n) { int sm, i; for(i = 1; i <= n; i++) sm += i; return sm; } int main() { int n = 10; int ans = get....sum(n); printf("%d", ans); return 0; }

55 | |

45 | |

35 | |

none of the mentioned |

Question 4 Explanation:

Since the variable "sm" is not initialized to 0, it will produce a garbage value.

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

What is the time complexity of the above iterative method used to find the sum of the first n natural numbers?

O(1) | |

O(n) | |

O(n ^{2}) | |

O(n ^{3}) |

Question 5 Explanation:

The time complexity of the above iterative method used to find the sum of first n natural numbers is O(n).

Once you are finished, click the button below. Any items you have not completed will be marked incorrect.

There are 5 questions to complete.