- /*
- 输入字符数字,在将其转换整形并倒序输出
- 思路:字符ascci码的关系
- */
- #include<iostream>
- using namespace std;
- int main()
- {
- int ch[50];
- int i=0;
- cout<<"请输入一个数:";
- while ( (ch[i]=getchar()) != '\\n')
- {
- ch[i] = ch[i]-'0'; // 将字符转换为整形并保存数组
- i++;
- }
- cout<<"你输入的数字倒序输出如下:"<<endl; //倒序输出
- for (int j=i-1; j>=0; j--)
- {
- cout<<ch[j];
- }
- cout<<endl;
- system("pause");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/191220138154.html
来源: http://www.codesnippet.cn/detail/191220138154.html