Algorithm to line up numbers with a specific digit sum of two numbers

count of n digit numbers whose sum of digits equals to given sum
compute sum of digits in all numbers from 1 to n
sum of digits of a number formula
write a program that asks the user for a number n and prints the sum of the numbers 1 to n
n digit numbers with digit sum s leetcode
n digit numbers with digit sum 's dynamic programming
sum of digits of a number in python
sum of digits of a number in c++

Im currently trying to create a Algorithm who is supposed to be able to line up numbers with a specific digit sum. For example numbers with a digit sum of 13 in between 1 and 500. Could someone give me some advice on how to proceed please?

My current progress:

 public class Digitsum{

static int Digitsum2(int number) {  //method to find out the digit sum from numbers between 1 and 500
    int sum = 0;
    if(number == 0){
        return sum;
    } else {
        sum += (number%10);

    return sum;

static int Digitsum13(int x) { //method to line up the numbers with a digit sum of 13

    while (x <= 500) {
    return x; 


public static void main(String[ ] args) {


Count of n digit numbers whose sum of digits equals to given sum , Given two integers 'n' and 'sum', find count of all n digit numbers with sum of digits as 'sum'. Leading 0's are not counted as digits. 1 <= n <= 100 and 1 <= sum  Given numbers A and B that are huge (maybe 20 decimal digits or more), determine the number of integers X with A ≤ X ≤ B that have a certain property P. SPOJ has lots of tasks like these for practice. Where examples of interesting properties include: "the digit sum of X is 60" "X consists only of the digits 4 and 7"

I'm posting a simple programme and think it will do your work.Because it was little bit difficult to understand your programme.

class Example{
public static void main(String args[]){

public static void digitsum(int num){
    int value;
    int copyofvalue;

    for(int i=1;i<500;i++){
        int sum=0;



If you have any problem with above programme, please let me know by a comment. If it suits your work mark it as an accepted answer.

Compute sum of digits in all numbers from 1 to n, Input: n = 5 Output: Sum of digits in numbers from 1 to 5 = 15 Input: n = 12 Output: Sum of digits in numbers of digits in a given number x Below is complete algorithm EXPLANATION FOR FIRST and SECOND TERMS IN BELOW LINE OF CODE The last two terms compute sum of digits in number from 300 to 328. The sum of digits of all k digit numbers, that is from $10^{(k-1)} \text { to } 10^k-1$, is $45*(10^k-1)/9$. Stopping part way is harder, but you can do it by recursion.

You want to find all the numbers within a particular range (1-500 in this case), the individual digits of which sum up to a particular target sum (13 in this case) and print a list of them.

public class Digitsum {

    static void digitSum(int target)
    System.out.println("Target: " + target);
        for(int i = 1; i <= 500; i++)
            int currsum = 0;
            int currnum = i;

            while(currnum > 0 )
                currsum += currnum%10;
                currnum /= 10;
            if( currsum == target)
                //print each match


    public static void main(String[] args) {
        System.out.println("Starting iteration from 1-500");

Test cases:

Starting iteration from 1-500 Target: 13 49 58 67 76 85 94 139 148 157 166 175 184 193 229 238 247 256 265 274 283 292 319 328 337 346 355 364 373 382 391 409 418 427 436 445 454 463 472 481 490

Starting iteration from 1-500 Target: 2 2 11 20 101 110 200

Starting iteration from 1-500 Target: 19 199 289 298 379 388 397 469 478 487 496

The Elements of Computing Systems: Building a Modern Computer from , Efficiency First Mathematical algorithms operate on «-bit binary numbers, with typical the multiplication operation x- y using the repeated addition algorithm for i = 1 To compute 356 times 27, we line up the two numbers one on top of the other. Next, we "shift to the left" one position, and multiply each digit of 356 by 2. Algorithm for Sum of two numbers. It's an algorithm for to find sum of two user defined numbers. *Not a program. To add two numbers. Read the Value of A and B. SUM = A+B. Display SUM. Stop.

Kahan summation algorithm, In numerical analysis, the Kahan summation algorithm, also known as compensated In particular, simply summing n numbers in sequence has a worst-case error that Similar, earlier techniques are, for example, Bresenham's line algorithm, Suppose we are using six-digit decimal floating-point arithmetic, sum has  The standard algorithm for addition has three simple rules: Rule 1: Line up the numbers vertically by matching the place values - and start with the ones place. To explain: When you add multi-digit numbers, the problem is typically written vertically - meaning one set of numbers is on top of the other.

Introduction to Cryptography with Mathematical Foundations and , The general algorithm for multiplying two numbers using their base b 3 8 We line up the two numbers at the right margin and begin by multiplying the Each time we get a product of digits larger than 9 (= b – 1), we have a carry that we move to the next digit (that will be added to the product). rows using base b addition. Algorithm to add two numbers in C: 1) Start. 2) Accept Number one. 3) Accept Number two. 4) Add both the numbers.

Arithmetic for Teachers: With Applications and Topics from Geometry, 27 2<4 (3.9) 28 4.7 +80 4.20 108 28 + 80 The algorithm begins with the horizontal line in such a way that the places of 28 line up with their respective places in the 4 times the digit in the ten's place of the multiplicand. the 2 in this example. If two whole numbers are expressed in the base ten numeration system, then  Explanation of algorithm to calculate digit sum of a number Algorithm Implementation at Send your queries at Up next Sum of FlowChart to Get the Sum of

  • Could you please add more examples (not in code, just input-output)
  • what is the meaning of "line up"?
  • input: Digitsum13(20); output: every number between 1 and 500 with a Digitsum of 20
  • line up = System.out.println(numbers between 1-500 with a Digitsum of 13)
  • Similar as that of…