所謂回文數是從左到右讀與從右到左讀都是一樣的數!例如7887,23432都是回文數.
不用數組方法:
1 #include<iostream>
2 using namespace std;
3 void main()
4 {
5 int i,x,y,r;
6 y=0;
7 cout<<"請輸入數 "<<endl;cin>>x;
8 i=x;
9 while(i!=0)
10 {
11 r=i%10;
12 i=i/10;
13 y=y*10+r;
14 }
15 if(y==x)
16 cout<<x<<" 是回文數"<<endl;
17 if(y!=x)
18 cout<<x<<" 不是回文數"<<endl;
19 }
運行結果:
但是超出范圍就出現錯誤了:
未完待續