c++的基础题目:
题目:输入任意两个整数,输出这两个整数之间的对称数,即回文数。
提示:对称数就是一个整数各位数字左右对称相等的,用自定义函数实现。
#include<iostream>
#include<iomanip>
using namespace std;
bool Number(const int m)
{
int k = 0, n;
n = m;
while (n > 0)
{
k = k * 10 + n % 10;
n /= 10;
}
if (k == m)
{
return true;
}
else
{
return false;
}
}
void funtion(int x, int y)
{
int i, j;
bool flag = false;
cout << x << "到" << y << "之间的对称数有:" << endl;
for (i = x; i <= y; i++)
{
flag = Number(i);
if (flag)
{
cout << left << setw(5) << i;
}
}
}
int main()
{
int i, j;
cout << "请输入两个整数:";
cin >> i >> j;
funtion(i, j);
cout << endl;
}