Question: Consider all codes made of four digits ( 0 9 ) . How many of them have a sum of digits equal to S ?

Consider all codes made of four digits (09). How many of them have a sum of digits equal to S? For example, for S =4, there are 35 such codes in total. Some of them are 0022,1003,1111,2020,4000.
Write a function:
int solution(int S);
that, given an integer S, returns the number of four-digit codes whose sum of digits is equal to S.
Examples:
For S =35, the possible codes are: 9998,9989,9899,8999. The function should return 4.
For S =4, the function should return 35.
For S =2, the function should return 10.
Assume that:
S is an integer within the range [0..36].
In your solution, focus oncorrectness. The performance of your solution will not be the focus of the assessment.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!