Chester0 Posted January 24, 2010 Share Posted January 24, 2010 (edited) Ive got this program: #include <stdio.h> #define I(i) i << 1 char text[] = { I(1), 50, I(3), I(0), I(7) }; char duma[] = "AB6789"; int main() { int i, j, k=1; k<<=1; for (;text[k] != 50;) { printf("%c", duma[k]); k=text[k] >> 1; } printf("=%3d+%s\n", k << 2, duma); return 0; } I'm not sure what #define I(i) i << 1 does, am guessing it's shifting left the values in the char text[] = { I(1), 50, I(3), I(0), I(7) } array? Like if i select text[4] the value will be 7 << 1 = 14? k=1 <<1 k=2 print duma[k]=6 k=3 print duma[k]=7 k=0 print duma[k]=A k=50 lol my bad k=1 here exit loop now for printf("=%3d+%s\n", k << 2, duma); i print an = %3d means 3 spaces and print?? k is 50 so 50 <<2 would make it 200 so i would print 3 spaces and 200? then just print "+" and duma. What i got so far: Screen: 67A= 200 4+AB6789 Correct Answer: 67A= 4+AB6789 i think am wrong with the %3d part? Problem solved :p Edited January 24, 2010 by Chester0 Link to comment Share on other sites More sharing options...
Question
Chester0
Ive got this program:
#include <stdio.h> #define I(i) i << 1 char text[] = { I(1), 50, I(3), I(0), I(7) }; char duma[] = "AB6789"; int main() { int i, j, k=1; k<<=1; for (;text[k] != 50;) { printf("%c", duma[k]); k=text[k] >> 1; } printf("=%3d+%s\n", k << 2, duma); return 0; }I'm not sure what #define I(i) i << 1 does, am guessing it's shifting left the values in the char text[] = { I(1), 50, I(3), I(0), I(7) } array?
Like if i select text[4] the value will be 7 << 1 = 14?
k=1 <<1
k=2
print duma[k]=6
k=3
print duma[k]=7
k=0
print duma[k]=A
k=50 lol my bad k=1 here
exit loop
now for printf("=%3d+%s\n", k << 2, duma);
i print an =
%3d means 3 spaces and print?? k is 50 so 50 <<2 would make it 200 so i would print 3 spaces and 200?
then just print "+" and duma.
What i got so far: Screen: 67A= 200 4+AB6789 Correct Answer: 67A= 4+AB6789
i think am wrong with the %3d part?
Problem solved :p
Edited by Chester0Link to comment
Share on other sites
0 answers to this question
Recommended Posts