求满足下列条件的最小自然数 x:(1)个位数是 8;(2)将个位数移至最高位,所得的新数是原数的 4 倍。
#include<iostream>
#include<cmath>
using namespace std;
/*求满足下列条件的最小自然数 x:(1)个位数是 8;(2)将个位数移至最高位,所得的新数是原数的 4 倍。
*/
int panduan(int x)
{
int count = 0;
int a = x % 10;
if (a == 8)
{
int d = x * 4;
int x1 = x;
while (x > 0)
{
x = x / 10;
if (x == 0)
break;
count++;
}
int c = a * pow(10, count) + x1 / 10;
if (d == c)
return 1;
else
return 0;
}
else
{
return 0;
}
}
int main()
{
int i = 10;
while (i > 0)
{
int b = panduan(i);
if (b == 1)
{
cout << i << endl;
break;
}
else
{
i++;
}
}
return 0;
}