Computer Science, asked by vishalnayakam05, 11 months ago

Given two integers N and K, find Z, the number of non-negative integers that are less than or equal to N and whose sum of digits is divisible by K.

Answers

Answered by abhyas29
0

I'll use java

public class Main {

public static void main(String[] args) {

int N = 10, K = 3, Z = 0;

int d, tmp;

// Input values here

// or use scanner if you want runtime inputs

while( N > 0 ) {

d = 0; // stores sum of digits

tmp = N;

while( tmp != 0 )

d += tmp % 10;

if ( d == K)

Z++;

N--;

}

System.out.println(Z);

}

}

Similar questions