sumDigits, then, finds the smallest integer between f and t (both inclusive) whose sum of digits is x, and returns that integer.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 22PE
icon
Related questions
Question
100%

Write a function(in pyhton) named sumDigits which takes three parameters: f, t and x.
sumDigits, then, finds the smallest integer between f and t (both inclusive)
whose sum of digits is x, and returns that integer. For example,
sumDigits(20, 30, 9) returns 27, because the smallest integer between 20 and 30
whose sum of digits is 9, is 27 (2+7=9):
20 -> 2+0 = 2
21 -> 2+1 = 3
22 -> 2+2 = 4
23 -> 2+3 = 5
24 -> 2+4 = 6
25 -> 2+5 = 7
26 -> 2+6 = 8
27 -> 2+7 = 9 ==> return 27

Your function should run for any f, t, and x value. If there is no such number,
then return -1.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning