Jump to content

Sum of the digits of n is substring of n: Difference between revisions

Add C++
(Add C)
(Add C++)
Line 90:
<pre>0 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 109 119 129 139 149 159 169 179 189 199 200 300 400 500 600 700 800 900 910 911 912 913 914 915 916 917 918 919</pre>
 
=={{header|C++}}==
<lang cpp>#include <iostream>
 
int digitSum(int n) {
int s = 0;
do {s += n % 10;} while (n /= 10);
return s;
}
 
int main() {
for (int i=0; i<1000; i++) {
auto s_i = std::to_string(i);
auto s_ds = std::to_string(digitSum(i));
if (s_i.find(s_ds) != std::string::npos) {
std::cout << i << " ";
}
}
std::cout << std::endl;
return 0;
}</lang>
{{out}}
<pre>0 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 109 119 129 139 149 159 169 179 189 199 200 300 400 500 600 700 800 900 910 911 912 913 914 915 916 917 918 919</pre>
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
2,125

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.