For the numbers between 1 to 1000 ,find all the numbers whose digit sum is 6. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

For the numbers between 1 to 1000 ,find all the numbers whose digit sum is 6.

21st Apr 2019, 9:34 AM
shu
shu - avatar
2 Answers
+ 15
Some points to calculate digit sum : ● use n%10 to take out last digit of n ● use n/=10 to remove last digit of n [works in Java] Run loop from 1 to 1000 & calculate digit sum in each iteration & by using == operator see whether its 6 or not. //for improving speed, you can put some more statements seeing whether sum of digits not exceed 6 else jump to next iteration, while calculating digitSum
21st Apr 2019, 1:28 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
Please show us your attempt first.
21st Apr 2019, 9:37 AM
HonFu
HonFu - avatar