Find the first N integers such that the sum of their digits is equal to 10 | C ++ implementation of the approach ; Function to return the sum of digits of n ; Add the last digit to the sum ; Remove last digit ; Return the sum of digits ; Function to print the first n numbers whose sum of digits is 10 ; First number of the series is 19 ; If the sum of digits of the current number is equal to 10 ; Print the number ; Add 9 to the previous number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sum ( int n ) { int sum = 0 ; while ( n ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } void firstN ( int n ) { int num = 19 , cnt = 1 ; while ( cnt != n ) { if ( sum ( num ) == 10 ) { cout << num << " ▁ " ; cnt ++ ; } num += 9 ; } } int main ( ) { int n = 10 ; firstN ( n ) ; return 0 ; }