实验2-4-1 统计各位数字之和是5的数 (20分)
程序员文章站
2022-07-04 12:23:13
...
实验2-4-1 统计各位数字之和是5的数 (20分)
代码:
int is( int number )
{
int sum = 0;
while (number > 0) {
sum += (number % 10);
number /= 10;
}
if(sum == 5) return 1;
return 0;
}
void count_sum( int a, int b )
{
int count = 0, sum = 0, i = 0;
for (i = a; i <= b; i++)
{
if (is(i) == 1) {
count++;
sum += i;
}
}
printf("count = %d, sum = %d", count, sum);
}