## 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?

Iteration | |

Recursion | |

Binomial coefficient | |

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?

nC2 | |

(n-1)C2 | |

(n+1)C2 | |

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?

sm = i | |

sm += i | |

i = sm | |

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; }

55 | |

45 | |

35 | |

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?

O(1) | |

O(n) | |

O(n ^{2}) | |

O(n ^{3}) |

**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.