标签:scanf ++ 区间 scan 多少 循环 span for bsp
试计算在区间 1 到 n 的所有整数中,数字 x(0 ≤ x ≤ 9)共出现了多少次?例如,在 1 到 11 中,即在 1、2、3、4、5、6、7、8、9、10、11 中,数字 1 出现了 4 次。
#include<stdio.h> int main() { int i,j,n,x,f=0; scanf("%d %d",&n,&x); for(i=1;i<=n;i++)//循环控制范围 for(j=i;j;j/=10)//分级数剥离数字计数 if(j%10==x) f++; printf("%d\n",f); return 0; }
标签:scanf ++ 区间 scan 多少 循环 span for bsp
原文地址:https://www.cnblogs.com/ZZ34/p/10427591.html