jeudi 19 janvier 2023

Find numbers with fixed length and fixed sum of digits

I have to solve the problem of finding the number of numbers having a length(i.e, number of digits) L(given as input) and sum of digits S(given also as input).

Well,my approach is to make L nested loops, each starting from i = 0(except the first loop which starts from i =1) to i = 9, and check if the sum of the iterators(wich represent the digits) of the loops is equal to S,and if so increment the counter by 1.

But since L is variable, i don't understand how to make L loops.
I read this post, but I still don't get how to write the code.
Any hint please?

Aucun commentaire:

Enregistrer un commentaire