C ++ uses recursive method to convert an integer n into a string

mission details

Recursively convert an integer n into a string. For example, if you enter 483, the character string "483" should be output. The number of bits of n is uncertain, and can be an integer with any number of bits.

Test input:

4399

Expected output:

4 3 9 9

Program source code:

#include <stdio.h> 
#include <iostream>
 using  namespace std; 

void splnum ( int n) 
{ 
    char num;
     if (n == 0 ) return ; 
    splnum (n / 10 ); 
    num = n% 10 + ' 0 ' ; // Make the digital makeup flower as the character 
    cout << num << "  " ; 
    
} 

int main () 
{ 
    
    // Please add code here 
    / * ********* Begin ****** ** * / 
    int nub; 
    cin>>nub;
    splnum(nub);
    /********** End **********/
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/junfblog/p/12705274.html