#include<stdio.h>
#include<stdlib.h>
int main(){
int num;
while(scanf("%d",&num) != EOF){
int regist = num ; 以regist變數做變動 ,
int times_square = 1 ; 預設次方數從1開始 ,
while(regist>10){ If 1234 > 10 ,
times_square = times_square * 10 ; times_square=10 , 100 , 1000 , but != 10000
regist = regist / 10 ; regist = 123 , 12 , 1 out of loop
int sum = 0 ;
while(num>0){ 這時候把原先的num叫出來做判斷 num=1234;
int residue = num / times_square ; 外迴圈把times_square乘到1000 thus 1234 / 1000 = 1
sum = sum + residue ; sum預設為0 , 0 + 餘數
printf("%d",residue) ; 印出餘數 (從times_square = 1000開始)
num = num % times_square ; 內迴圈這行指令應該為 1234 / 1000 的餘數 == 234 ,
接著再繼續此內迴圈(234>0)
if (num>0){ 判斷內迴圈(234>0) (34>0) (4>0) break
printf("+") ;
}
else if(num<=0){ 當4繼續除於10時 , 比0小 印出等號
printf("=") ;
}
times_suqare = times_square / 10 ; e.g. 1234/1000 234/100 34/10 4/1
}
printf("%d\n,sum) ;
}
}
此程式似乎是有點問題的,如果尾數輸入0的數字,會出現不一樣的狀況
(有待修正)
留言列表