题解 | 牛牛数数
牛牛数数
https://www.nowcoder.com/practice/03a3cc96fa4847b387bf58bb800d67cf
#include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int high = 0; // 存储位数
int temp = i; // 临时变量
//high会遍历所有位数,而while循环条件为high不等于4,所以只要有一个位数是4,就会不进入循环,high保留为4,而if判断中也有high不等于4,所以不会打印
while (temp > 0&&high!=4)
{
high = temp % 10; // 每次取当前最后一位
temp = temp / 10; // 去掉最后一位
}
if (i % 4 != 0 && high != 4)//排除四的倍数 和 数位为4的情况
{
printf("%d\n", i);
}
}
return 0;
}

查看21道真题和解析