#25816: C language 簡易寫法


22207807 (會打Code的貓)

學校 : 逢甲大學
編號 : 156777
來源 : [140.134.241.201]
最後登入時間 :
2023-03-14 12:33:09
a149. 乘乘樂 | From: [114.137.217.137] | 發表日期 : 2021-06-24 16:32

#include<stdio.h>

#include<math.h>

int main () {

int tem,a,n,p,total,s[10000] = {0};

scanf("%d",&n);

for(int j = 0; j < n; j++) {

int b;

scanf("%d",&b);

p = 0; total = 1; tem = b;

while(tem != 0) {

s[p++] = tem /= 10;

}

tem = b;

for(int i = p - 1; i >= 0; i--) {

a = pow(10,i);

s[i] = tem / a;

tem %= a;

total *= s[i];

}

if(b == 0) {

printf("0");

}else {

printf("%d\n",total);

}

 

}

return 0; 

total為最後答案,初始值為1

p為b有多少位

tem微暫存b的值

注意b為0時候

 
ZeroJudge Forum