[英]Any idea how to convert and Octal number to a decimal with recursion?
我想使用遞歸將八進制數轉換為十進制數。 到目前為止,我可以輸入正確的數字,但是倒退,我仍然需要調換訂單,我該怎么做? 我的代碼(給出倒數):
void decimalToOctal(int num) {
int total = 0;
if (num > 0)
{
total = num % 8;
num /= 8;
cout << total;
decimalToOctal(num);
}
}
想象一下,如果正確的十進制數字為234,則此代碼為432。
只需將打印輸出移動到遞歸后,就像這樣
void decimalToOctal(int num) {
int total = 0;
if (num > 0)
{
total = num % 8;
num /= 8;
decimalToOctal(num);
cout << total;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.