遞歸法將一個整數n轉換成字符串


用遞歸法將一個整數n轉換成字符串

任務描述

用遞歸法將一個整數n轉換成字符串。例如,輸入483,應輸出字符串“483”。n的位數不確定,可以是任意位數的整數。

測試輸入:

4399

預期輸出:

4 3 9 9

測試輸入:

10010

預期輸出:

1 0 0 1 0

源代碼:

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


int main()
{
    
    // 請在此添加代碼
    /********** Begin *********/
	int n;
	cin>>n;
	int a[100]={0},i;
	for(i=0;n>0;i++){
        a[i] = n%10;
        n/=10;
    }
    for(i=i-1;i>=1;i--){
        cout<<a[i]<<" ";
    }
    cout<<a[i];
    
    /********** End **********/
    return 0;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM