Re: [問題] 面試考題
Environment : winXP sp2,Code:Block 10.5,gcc 4.4.1
sample code
=============================================================
#include <stdio.h>
#include <stdlib.h>
int main()
{
char src[12] = {0};
int temp = 0;
int cnt = 0;
int i = 0;
scanf("%s",src);
for (;;){
cnt = strlen(src);
if (cnt < 2){
break;
}
temp = 0;
for (i=0;i<cnt;i++){
temp += src[i] - '0'; //重點
}
sprintf(src,"%d",temp);
}
printf("result = %s",src);
return 0;
}
input : 454
output : 4
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.64.95
推
08/10 18:10, , 1F
08/10 18:10, 1F
→
08/11 07:23, , 2F
08/11 07:23, 2F
→
08/11 07:24, , 3F
08/11 07:24, 3F
→
08/11 07:25, , 4F
08/11 07:25, 4F
討論串 (同標題文章)