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

Recursion | |

Iteration | |

Greedy algorithm | |

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?

1 | |

16 | |

36 | |

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?

0 | |

1 | |

16 | |

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?

sm += n | |

sm += n%10 | |

sm += n-10 | |

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

1 | |

3 | |

7 | |

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.

There are 5 questions to complete.