## 8/29/2011

### f(N) counts number of '1'. For example f(13) = 6. So f(1)=1. What next number do satisfy the rule?

f(N) counts number of '1'. For example f(13) = 6. So f(1)=1. What next number do satisfy the rule?

---------------------------------------------------

์์ n์ ๋ํด์ 1๊ณผ n ์ฌ์ด์ 1์ด ๋์ค๋ ํ์๋ฅผ ๋ํ๋ด๋ ํจ์๋ฅผ f(n)์ด๋ผ๊ณ  ํ๋ค. ์๋ฅผ ๋ค์ด f(13)=6์ด๋ค. f(n)=n์ด ๋๋ ์ฒซ๋ฒ์งธ ์์๋ 1์ด๋ค. ๋๋ฒ์งธ ์์๋ ๋ฌด์์ธ๊ฐ?

1. This is my code.
Let's compare to each code.
Bye Bye~ ^^

int CountOne(int input)
{
int count =0;
while(1)
{
if( input%10 == 1)
count++;
input = input/10;

if(input == 0)
break;
}

return count;
}

int main()
{
int i=2;
int count=1;

while(1)
{

count += CountOne(i);

if( i == count)
break;

i=i+1;

}

printf("f(%d) = %d\n", i, count);

return 0;
}

2. Anonymous30/8/11 00:16

JeKang's code:

#include

void main()
{
unsigned long Num, End, Temp;

Num=0;
End=0;

while(Num<=1 || Num!=End){
Num+=1;
Temp=Num;

while(Temp!=0){
if(Temp%10==1) End+=1;
Temp=(unsigned long)(Temp/10);
}

}
printf("์๋ ฅ๊ฐ Num = %d\n๊ฒฐ๊ณผ๊ฐ End = %d\n",Num,End);
}

3. ์ ๊ฐ์ ์์ค ์ ์งฐ๋ค..
๋ด๊ฐ ๋ณผ๋๋, while๋ฌธ ์กฐ๊ฑด์ด ์กฐ๊ธ ๋ณต์กํด์ ๋์ค์ ๋ณด๋ฉด ์ดํด๊ฐ ์ฝ๊ฒ ์๊ฐ ๊ฒ ๊ฐ๊ณ ..
while๋ฌธ ์์ while๋ฌธ์ ํน์  ์ผ๋ง ํ๋๊น ํจ์๋ก ๋ง๋ค๋ฉด ์์ค๊ฐ ๋ ๊ฐ๊ฒฐํด ์ง ๊ฒ ๊ฐ๋ค.
์ํ๋ค..
Good job~!!

4. Anonymous1/9/11 02:46

JeKang :

๋ค ํจ์๋ก๋ ๋ง๋ค์ด ๋ณผ๊ป์. ๊ฐ์ฌํฉ๋๋ค~

5. Anonymous2/9/11 03:21

๋ฏผํ๊ท

#include
#include

int fun(char* a);

void main()
{
int d;
int p=0;
int i=0;
char a[20]={0,};
printf("์ซ์์๋ ฅํ์ธ์:");
scanf("%d",&d);

for(i=0;i<=d;i++)
{
itoa(i,a,10);
p=p+fun(a);
if(p==i)
printf("%d\n",p);

}

}

int fun(char* a)
{
int i=0;
int count=0;
for(i=0;i<= 20 ;i++)
{
if(a[i]=='1') count+=1;
}
return count;
}