这种方法加以扩展,可以用于其他进制的数进行转换
- #include<iostream>
- using namespace std;
- void ItoC(char*A ,int m,int &counter)
- {
- int temp1,temp2;
- counter=1;
- temp1 = m%10;
- temp2 = m/10;
- A[0]=temp1+48;
- while(temp2 != 0)
- {
- m=temp2;
- temp1 = m%10;
- temp2 = m/10;
- A[counter++]=temp1+48;
- }
- }
- int main()
- {
- char A[10];
- int counter;
- ItoC(A,34562,counter);
- for(int i=0;i<counter;i++)
- cout<<A[i]<<"/t";
- cout<<endl;
- while(counter-- >0)
- cout<<A[counter]<<"/t";
- cout<<endl;
- return 0;
- }