Thread: What is the logic for this program

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    33

    What is the logic for this program

    Dear All,
    I was attended recently one interview in MNC company..they told me to explain the logic of following program and they provided output for me..it is the first time i am seeing this type of c program in my industry experience
    program is follows

    Code:
    #include<stdio.h>
    int main()
    {
         int a, b, c;
         int count=1;
         for(b=c=10;a="-FIGURE?,UMKC,XYZHello Folks,TFy!QJu R0o TNn(R0o)SLq SLq ULo+ UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
                       NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
                       HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
                       T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
                       Hq!WFs XDt!" [b+++21];)
                       for(;a-->64;)
                       putchar(++c=='Z'?c=c/9:33^b&1);
                       system("pause");
                       return 0;
                       }
    It will give the output as INDIAN COUNTRY symbol..can anybody explain me what is the logic behind this program

  2. #2
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    It's like this:

    Code:
    #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,"&#37;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;# \
    ){nl]!/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(31[a]):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);}
    It seems to make no sense, but infact it prints out the song of 12 days of christmas. The logic is hidden so no one else or very few can manage to make sense of it

    Btw the code you posted is not in it's entirety? Because it gives several warnings and doesn't print right.

  3. #3
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    This may help:

    The process is known as obfuscated code.

    http://en.wikipedia.org/wiki/Obfuscated_code

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    It won't compile anyway. And by the looks of it, it doesn't seem they meant for it to be obfuscated...
    Code:
    #include<stdio.h>
    int main()
    {
         int a, b, c;
         int count=1;
         for(b=c=10;a="-FIGURE?,UMKC,XYZHello Folks,TFy!QJu R0o TNn(R0o)SLq SLq ULo+ UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
                       NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
                       HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
                       T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
                       Hq!WFs XDt!" [b+++21];)
                       for(;a-->64;)
                       putchar(++c=='Z'?c=c/9:33^b&1);
                       system("pause");
                       return 0;
                       }

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > it is the first time i am seeing this type of c program in my industry experience
    If someone produced code for me looking like that, I would sack them on the spot.

    If asked at an interview what that code was doing, I'd walk out as they're obviously a bunch of idiots and not worth working for.

    If I saw that in some code, I'd rewrite the thing in something far more palatable.

    That is in no way representative of industry code, it is merely some jerk with too much time on their hands trolling through IOCCC entries.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. logic on a program
    By officegirl in forum C Programming
    Replies: 0
    Last Post: 10-13-2001, 10:41 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM