题解 | #挑7#

挑7

http://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b

#include <stdio.h> int main(void) { int num,count = 0; scanf("%d",&num); //输入这个数字 getchar();

for(int i=1; i<=num; i++)
{
    int temp=i;
    if(temp%7==0) //如果是7的倍数需要计数器加1
        count ++;
    else
        while(temp) //然后检查该数字里面是否含有数字7
        {
            if(temp%10==7)  //%10可以取个位
            {
                count ++;
                break;
            }
            temp/=10; // /10可以将每一位移动到个位
        }
}
printf("%d\n",count);
return 0;

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务