Data Structure Questions and Answers-Sum of Digits of a Number using Recursion

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Sum of Digits of a Number using Recursion

Congratulations - you have completed Data Structure Questions and Answers-Sum of Digits of a Number 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 digits of a number?
A
Recursion
B
Iteration
C
Greedy algorithm
D
Both recursion and iteration
Question 1 Explanation: 
Both recursion and iteration can be used to find the sum of digits of a number.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What can be the maximum sum of digits for a 4 digit number?
A
1
B
16
C
36
D
none of the mentioned
Question 2 Explanation: 
The sum of digits will be maximum when all the digits are 9. Thus, the sum will be maximum for the number 9999, which is 36.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What can be the minimum sum of digits for a 4 digit number?
A
0
B
1
C
16
D
36
Question 3 Explanation: 
The sum of digits will be minimum for the number 1000 and the sum is 1.

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Consider the following iterative implementation to find the sum of digits of a number:

#include<stdio.h> int sum....of....digits(int n) { int sm = 0; while(n != 0) { .....; n /= 10; } return sm; } int main() { int n = 1234; int ans = sum....of....digits(n); printf("%d", ans); return 0; }

Which of the following lines should be inserted to complete the above code?

A
sm += n
B
sm += n%10
C
sm += n-10
D
sm += n/10
Question 4 Explanation: 
The line "sm += n % 10" adds the last digit(LSB) of the number to the current sum. Thus, the line "sm += n%10" should be added to complete the above code.

Question 5 [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 sum....of....digits(int n) { int sm = 0; while(n != 0) { sm += n%10; n /= 10; } return sm; } int main() { int n = 1234; int ans = sum....of....digits(n); printf("%d", ans); return 0; }
A
1
B
3
C
7
D
10
Question 5 Explanation: 
The above code prints the sum of digits of the number 1234, which is 10.

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