#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
using namespace std;
//判断一个数是否被7整除或者数中包含7
int reversal(int x); //声明函数
int main()
{
int n = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
if (i % 7 == 0 || reversal(i))
{ //利用或来进行只满足条件之一就输出
cout << i << " ";
}
}
return 0;
}
int reversal(int x)
{ //判断整数是否含7的
int remain = 0, b = 0;
while (x)
{
remain = x % 10;
if (remain == 7)
{
return true;
}
x = x / 10;
}
return false;
}
判断一个整数是否能被7整除或者数中含7
最新推荐文章于 2023-03-02 17:56:10 发布