2016年5月1日 星期日

[C_MM063-易] N階層末尾0的數量

[C_MM063-易] N階層末尾0的數量




#include&ltstdio.h&gt  
int main(){     
   int num,tot=0,five=0,temp;  
    scanf("%d",&num);  
    temp=num;  
    while(temp){  
        five+=temp/5;  
        temp/=5;  
    }  
    printf("%d\n",five);  
    return 0;   
 /* 
    題目:N階層末尾0的數量
    作者:1010
    時間:西元 2016 年 5 月 */
} 

把num除以5的餘數加起來再num/5直到num=0

沒有留言:

張貼留言