Shinnara's Blog
Talking with Shinnara :: NaraTalk.com

'unixc'에 해당되는 글 2건

  1. 2007/11/21 mystery.c
  2. 2007/11/21 [UNIX-C] C/C++ Program Compilation

mystery.c

Computer/Programming/C/C++ 2007/11/21 15:23 by Shinnara

UNIX-C 튜토리얼을 보다가 보게된 프로그램입니다.


#include <stdio.h>

main(t,_,a)
char *a;
{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, _+1, "%s %d %d\n" ):9:16:t<0?t<-72?main(_,
t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+\
,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/\
+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){n\
l]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#\
n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;\
#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/")
:t<-50?_==*a ?putchar(a[31]):main(-65,_,a+1):main((*a == '/')+t,_,a\
+1 ):0<t?main ( 2, 2 , "%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc \
i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}


참으로 난해하게 보이는 코드입니다. 저렇게 코드를 짠다면 아마 무지 혼낼것 같습니다~ 하지만 조금만 들여다보면 어떻게 동작하는 지를 알수 있는 코드이기도 하지요.

다음은 실행 결과 입니다.

On the first day of Christmas my true love gave to me
a partridge in a pear tree.

On the second day of Christmas my true love gave to me
two turtle doves
and a partridge in a pear tree.

On the third day of Christmas my true love gave to me
three french hens, two turtle doves
and a partridge in a pear tree.

On the fourth day of Christmas my true love gave to me
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the fifth day of Christmas my true love gave to me
five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the sixth day of Christmas my true love gave to me
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the seventh day of Christmas my true love gave to me
seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the eighth day of Christmas my true love gave to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the ninth day of Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the tenth day of Christmas my true love gave to me
ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the eleventh day of Christmas my true love gave to me
eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the twelfth day of Christmas my true love gave to me
twelve drummers drumming, eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.


이해는 되지만, 그래도 신기하긴합니다 ^^




TAG c, mystery.c, unixc
0 Trackback, 0 Comment

TRACKBACK :: http://naratalk.com/trackback/232 관련글 쓰기

댓글을 달아 주세요


C를 다시 정복하고 싶은 제 마음을 적은 바 있는데요, 그래서 바로 시작을 했습니다. 환경은 FreeBSD 6.2, gcc 3.4.6 환경입니다.

앞선 포스팅에서 좋은 자료로 소개한 것 중에 Unix C 에 대한 자료로 일단 시작을 해보았는데, 거기에 있는 내용 중에 도움이 될 만한 자료들을 추려보려고 합니다. 특히 연습 문제를 위주로 하여 진행 하고자 합니다.

첫번째 내용이 C로 프로그래밍을 하여 컴파일하고 실행하는 것에 대한 내용입니다. 자세한 내용은 원본 문서를 확인해주시면 되구요.

연습문제를 풀어보도록 하겠습니다.

Exercise 12172

The following program uses the math library. Enter compile and run it correctly.

#include <math.h>

main()

{ int i;

printf("\t Number \t\t Square Root of Number\n\n");

for (i=0; i<=360; ++i)
printf("\t %d \t\t\t %d \n",i, sqrt((double) i));
}

위의 프로그램을 컴파일하고 제대로 실행하라는 문제군요. 라이브러리를 어떻게 쓰는지에 대한 문제입니다.

위의 내용대로 코드를 입력하고 컴파일을 해봅니다.

[shinnara ~/work/c/unixc]$ gcc exer12172.c
/var/tmp//ccEk6OYt.o(.text+0x4a): In function `main':
: undefined reference to `sqrt'
[shinnara ~/work/c/unixc]$

역시나 sqrt 가 정의되어 있지 않다고 나옵니다. -l 옵션을 붙여줘야 합니다.

[shinnara ~/work/c/unixc]$ gcc exer12172.c -lm
[shinnara ~/work/c/unixc]$

gcc 옵션과 관련된 자세한 내용은 Gcc 와 Make 강좌를 참조하시기 바랍니다.

컴파일이 제대로 되었으니, 이제 실행을 해봐야 할텐데요. a.out 이 디폴트로 생겼으니 실행을 해봅니다.

[shinnara ~/work/c/unixc]$ ./a.out
Number Square Root Of Number

0 0.00
1 1.00
2 1.41
...
353 18.79
354 18.81
355 18.84
356 18.87
357 18.89
358 18.92
359 18.95
360 18.97
[shinnara ~/work/c/unixc]$

그런데 실행된 모습이 다르다구요? 네, 맞습니다. 위의 프로그램을 조금 변경했습니다. 아래는 제 소스입니다.


[shinnara ~/work/c/unixc]$ cat exer12172.c
#include <math.h>

main()
{
int i;

printf("\t Number \t\t Square Root Of Number\n\n");

for(i=0;i<=360;i++)
printf("\t %d \t\t %.2f\n",i,sqrt((double) i ));
}
[shinnara ~/work/c/unixc]$


이제, 다들 제대로 동작하시죠?









TAG c, compile, unixc
0 Trackback, 0 Comment

TRACKBACK :: http://naratalk.com/trackback/231 관련글 쓰기

댓글을 달아 주세요

1 
다...... (264)
Computer/Programming (106)
Links (14)
책 읽는 즐거움 (7)
끄적임 (66)
즐거운 과학 나라 (7)
일본 (5)
Study (4)