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

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

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

Click on any option to know the CORRECT ANSWERS

Question 1
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
Bank exam Questions answers

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

Question 2
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
Library science Questions answers

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
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
History Questions answers

Question 3 Explanation: 
The line "sm += i" completes the above code.

Question 4
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
Civics Test Questions answers

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

Question 5
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)
Civics Test Questions answers

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

There are 5 questions to complete.

 

 Download all FREE PDF Ebook >>>CLICK HERE<<<