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

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?
A
Iteration
B
Recursion
C
Binomial coefficient
D
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?
A
nC2
B
(n-1)C2
C
(n+1)C2
D
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?

A
sm = i
B
sm += i
C
i = sm
D
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; }
A
55
B
45
C
35
D
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?
A
O(1)
B
O(n)
C
O(n2)
D
O(n3)
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. Get Results
There are 5 questions to complete.

DOWNLOAD FREE PDF <<CLICK HERE>>