文章
16
粉丝
0
获赞
59
访问
3.0k
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int countDigitTwo(int num){
int count = 0;
while(num > 0){
if(num % 10 == 2){//查看个位数是否为2
count++;
}
num /= 10;//降一位
}
return count;
}
int main(){
int L,R;
scanf("%d %d",&L,&R);
int totalCount = 0;
for(int i = L;i <= R;i++){
totalCount += countDigitTwo(i);
}
printf("%d\n",totalCount);
return 0;
}
登录后发布评论
暂无评论,来抢沙发