你拿到一個整數,卻忍不住想把每個位數都乘在一起。例如看到 356 就會想要知道 3 * 5 * 6 的值為何。快寫個程式幫幫為了乘數字而快發瘋的自己吧!
輸入說明 :
一開始有一個數字 T,表示共有幾組測試資料。
接下來有 T 個數字 n (0 <= n < 2147483648)。
輸出說明 :
輸出可以拯救自己的結果。
範例輸入 :
3
356
123
9999
範例輸出 :
90
6
6561
程式碼 :
#include<stdio.h>
int main()
{
int i,n,T,temp,total;
scanf("%d",&T);
for(i=0; i<T; i++)
{
scanf("%d",&n);
if(n!=0)
{
total = 1;
while(n != 0)
{
temp = n % 10;
n /= 10;
total *= temp;
}
}
else
total = 0;
printf("%d\n",total);
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=a149
while(n != 0)
回覆刪除{
temp = n % 10;
n /= 10;
total *= temp;
}
這邊寫得真好!
感謝!
回覆刪除希望你可以學到更多東西