撰寫遞回函式int count(int n),統計任意正整數n的位數,在main函式中輸入整數m,然后呼叫遞回函式輸出統計結果。
uj5u.com熱心網友回復:
#include <stdio.h>
int count(int n);
int main()
{
int m;
scanf("%d", &m);
printf("%d\n", count(m));
return 0;
}
int count(int n)
{
static int bit;
if (n == 0)
return 0;
bit++;
count(n/10);
return bit;
}
供參考~
uj5u.com熱心網友回復:
int count(int n){
return n < 10 ? 1 : count(n / 10) + 1;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284367.html
標籤:C語言
