[C++][東方哈佛電機系] 資概作業4_將整數值轉成字元序列




#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    /*
       input num  =  1234567  /  234567  /  67  /  6 ...  value
       remain     =   234567  /   34567  /   7  /  0 ...  RR
       leading    =        1  /       2  /   6  /  6 ...  AA
       print      =        1  /       2  /   6  /  6 ...  BB
    */
   
    int value, RR, AA, BB;
    double aa, bb;
 
    cout << "enter an integer: ";
    cin >> value;
    cout << endl;
 
    RR = value;
 
    do{
        aa = pow(10, floor(log10((double)RR)));
        AA = (int)aa;
     
        bb = RR / AA;   // (int)/(int) -> (float
        BB = (int)bb;
        printf("%d\t", BB);
     
        RR = RR % AA;    
    }while (RR != 0);
 
    cout << endl << endl;
 
    system("pause");
    return 0;
}