+ 1
For the numbers between 1 to 1000 ,find all the numbers whose digit sum is 6.
2 ответов
+ 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
+ 5
Please show us your attempt first.