编制程序判断用户输入的一个整型数是不是a.回文数,b.素数,c.回文素数,要求只能输出一个答案
#include <iostream>
using namespace std;
int isp(int n) {
int i;
for (i = 2; i <= n/2; i++) {
if (n % i == 0)
return 0;
}
return 1;
}
int ish(int n) {
int m = n, t = 0;
while (m) {
t = t * 10 + m % 10;
m /= 10;
}
return t == n;
}
int main() {
int x;
cout << "Input x:";
cin >> x;
if (isp(x) && ish(x))
cout << "huiwen su shu";
else if (isp(x))
cout << "su shu";
else if (ish(x))
cout << "huiwen.";
else
cout << "no.";
return 0;
}
#include <iostream>
using namespace std;
int isp(int n) {
int i;
for (i = 2; i <= n/2; i++) {
if (n % i == 0)
return 0;
}
return 1;
}
int ish(int n) {
int m = n, t = 0;
while (m) {
t = t * 10 + m % 10;
m /= 10;
}
return t == n;
}
int main() {
int x;
cout << "Input x:";
cin >> x;
cout << x << " is a ";
if (ish(x))
cout << "huiwen";
if (isp(x))
cout << " prime";
cout << " number." << endl;
return 0;
}