下面是用C语言统计1到1000内所有位数和为15的代码
#include<stdio.h>
int main()
{
for (int i = 1; i <= 1000; i++)
{
if (i < 10)
{
continue;
}
else if(i >= 10 && i <100)
{
int a = i % 10;
int b = i / 10;
if (a + b == 15)
{
printf("%d\n", i);
}
}
else if(i >= 100 && i < 1000)
{
int c = i % 10;
int d = i / 10 % 10;
int e = i / 100;
if (c + d + e == 15)
{
printf("%d\n", i);
}
}
}
return 0;
}