本題要求編寫程式,對輸入的乙個整數,從高位開始逐位分割並輸出它的各位數字。
輸入在一行中給出乙個長整型範圍內的非負整數。
從高位開始逐位輸出該整數的各位數字,每個數字後面有乙個空格。
1 2 3 4 5 6方案1:常規方法
#include
#include
intmain()
int number=1;
//用於表示數字每一位
while
(a)}
for(i;i>
0;i--
)//迴圈提前結束,i不為0。若迴圈正常結束,則i=0
printf
("%d ",0
);return0;
}
方案2:使用遞迴函式,此法無須考慮n末位是否為0
#include
void
reverse
(int a)
;int
main()
void
reverse
(int n)
}
C 獲取整數各位數字
設定輸入正整數,獲取各位數字。第一種方式 注意 預設為9位,比如說輸入123,則輸出 從個位向更高位輸出 會是3 2 1 0 0 0 0 0 0,也就是說更高位會輸出0。如下 includeusing namespace std const long a int main long num int ...
正序輸出各位數字
題目描述 輸入乙個整數,從高位開始逐位分割並輸出各位數字。輸入輸入乙個正整數n,n是int型資料。輸出依次輸出各位上的數字,每乙個數字後面有乙個空格,輸出佔一行。例如,輸入 12345 輸出 1 2 3 4 5。思路 子函式來統計位數,主函式來取數 include using namespace s...
正序逆序輸出正整數中各位數字
一 輸出整數各位數字 求出它是幾位數 分別列印出每一位數字 按逆序列印出各位數字。define crt secure no warnings include include intgetdigit int num 整數有多少位 return count void reprintnum int num...