to generate the general no between 1to10 write the general syntax
Answers
Answered by
1
Given a number n, find sum of digits in all numbers from 1 to n.
Examples:
Input: n = 5
Output: Sum of digits in numbers from 1 to 5 = 15
Input: n = 12
Output: Sum of digits in numbers from 1 to 12 = 51
Input: n = 328
Output: Sum of digits in numbers from 1 to 328 = 3241
Naive Solution:
A naive solution is to go through every number x from 1 to n, and compute sum in x by traversing all digits of x. Below is the implementation of this idea.
filter_none
Similar questions