实验2-4-1 统计各位数字之和是5的数 (20分)




http://pta.patest.cn/pta/test/13/exam/3/question/411





#include
int is( int number );
void count_sum( int a, int b );
int main() {
int a, b;
scanf("%d %d", &a, &b);
if (is(a)) printf("%d is counted.\n", a);
if (is(b)) printf("%d is counted.\n", b);
count_sum(a, b);
return 0;
}
int is(int number) {
//1526
int c,d;
int sum=0;
while(number!=0) {
c=number%10;
sum=sum+c;
number=number/10;
}
if(sum==5) {
return 1;
} else {
return 0;
}
}//104   999
void count_sum( int a, int b ) {
int i;
int sum1=0;
int count=0;
for(i=a; i<=b; i++) {
if(is(i)) {
count++;
sum1=sum1+i;
}
}
printf("count = %d, sum = %d",count,sum1);
}



你可能感兴趣的:(C语言)